Thread: [Cppunit-devel] Running subset of CPPUnit tests in non-interactive mode
Brought to you by:
blep
|
From: Srivalli A. <sar...@ya...> - 2005-12-22 19:33:23
|
Hi!
I have written a few testcases in one testsuite using CPPUnit in non-interactive mode (console application). I am trying to provide an option of running a subset of testcases.
When I try to get name of a testcase it returns only the suite name.
CPPUNIT_NS::Test *suite = CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
CPPUNIT_NS::Test *childTest = suite->getChildTestAt( 0 );
cout << "ChildTestName is: " << childTest->getName() << endl;
CPPUNIT_NS::Test *childTest2 = suite->getChildTestAt( 1 );
cout << "ChildTestName2 is: " << childTest2->getName() << endl;
How can I get name of testcase that is within the suite?
Is there an example of running subset of tests using CPPUnit in non-interactive mode?
Thanks
Srivalli.
---------------------------------
Yahoo! DSL Something to write home about. Just $16.99/mo. or less |
|
From: <vri...@us...> - 2005-12-23 10:08:07
|
> When I try to get name of a testcase it returns only the suite name.=20
>=20
> CPPUNIT_NS::Test *suite =3D =
CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
> CPPUNIT_NS::Test *childTest =3D suite->getChildTestAt( 0 );
> cout << "ChildTestName is: " << childTest->getName() << endl;
>=20
> CPPUNIT_NS::Test *childTest2 =3D suite->getChildTestAt( 1 );
> cout << "ChildTestName2 is: " << childTest2->getName() << endl;
Sorry, but for me it works as expected.
I use the lastest CVS version.
I have 2 tests :
class AssertMemoryTest : public CPPUNIT_NS::TestFixture { ... }
CPPUNIT_TEST_SUITE_REGISTRATION(AssertMemoryTest);
class AssertStringTest : public CPPUNIT_NS::TestFixture { ... }
CPPUNIT_TEST_SUITE_REGISTRATION(AssertStringTest);
When I run your code, I get the names of my 2 tests :
AssertMemoryTest=20
AssertStringTest
You may have made a mistake somewhere else.
First of all, try this just after calling makeTest():
int count =3D suite->getChildTestCount();
In my case, I get count =3D=3D 2.
And you ?
Good luck.
Vincent Rivi=E8re.
|
|
From: Srivalli A. <sar...@ya...> - 2005-12-23 18:21:23
|
My scenario is slightly different. I have one test-suite and two testcases within that suite. Here is how my class and registration looks like:
class RPTest : public CPPUNIT_NS::TestFixture{
CPPUNIT_TEST_SUITE( RPTest );
CPPUNIT_TEST( testConnection );
CPPUNIT_TEST( testSession );
CPPUNIT_TEST_SUITE_END();
public:
....
};
CPPUNIT_TEST_SUITE_REGISTRATION( RPTest );
I want to print names of testcases within the test suite like
testConnection
testSession
How can I do this?
Anyone tried to run subset of testcases within a test-suite in non-interactive mode? Any suggestions?
Thanks
Srivalli.
Vincent Rivière <vri...@us...> wrote:
> When I try to get name of a testcase it returns only the suite name.
>
> CPPUNIT_NS::Test *suite = CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
> CPPUNIT_NS::Test *childTest = suite->getChildTestAt( 0 );
> cout << "ChildTestName is: " << childTest->getName() << endl;
>
> CPPUNIT_NS::Test *childTest2 = suite->getChildTestAt( 1 );
> cout << "ChildTestName2 is: " << childTest2->getName() << endl;
Sorry, but for me it works as expected.
I use the lastest CVS version.
I have 2 tests :
class AssertMemoryTest : public CPPUNIT_NS::TestFixture { ... }
CPPUNIT_TEST_SUITE_REGISTRATION(AssertMemoryTest);
class AssertStringTest : public CPPUNIT_NS::TestFixture { ... }
CPPUNIT_TEST_SUITE_REGISTRATION(AssertStringTest);
When I run your code, I get the names of my 2 tests :
AssertMemoryTest
AssertStringTest
You may have made a mistake somewhere else.
First of all, try this just after calling makeTest():
int count = suite->getChildTestCount();
In my case, I get count == 2.
And you ?
Good luck.
Vincent Rivière.
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
Cppunit-devel mailing list
Cpp...@li...
https://lists.sourceforge.net/lists/listinfo/cppunit-devel
---------------------------------
Yahoo! for Good - Make a difference this year. |
|
From: <vri...@us...> - 2005-12-24 15:02:25
|
> My scenario is slightly different. I have one test-suite and two =
testcases within that suite. Here is how my class and registration =
looks like:
>=20
> class RPTest : public CPPUNIT_NS::TestFixture{
> CPPUNIT_TEST_SUITE( RPTest );
> CPPUNIT_TEST( testConnection );
> CPPUNIT_TEST( testSession );=20
> CPPUNIT_TEST_SUITE_END();
> public:
> ....
> };
>=20
> CPPUNIT_TEST_SUITE_REGISTRATION( RPTest );
>=20
> I want to print names of testcases within the test suite like
> testConnection
> testSession
>=20
> How can I do this?
You have to go on step deeper !
TestFactoryRegistry::makeTest() returns a tree of Test.
The childs are the test classes.
The childs of the childs are the test methods.
So if you try :
CPPUNIT_NS::Test *childTest =3D suite->getChildTestAt( 0 );
CPPUNIT_NS::Test *methodTest =3D childTest->getChildTestAt( 0 );
cout << "MethodTestName is: " << methodTest->getName() << endl;
You will get : "RPTest::testConnection"
It should be good !
> Anyone tried to run subset of testcases within a test-suite in =
non-interactive mode? Any suggestions?
Try this :
CPPUNIT_NS::Test* testToRun =3D =
suite->findTest("RPTest::testConnection");
...
Vincent.
|
|
From: <vri...@us...> - 2006-01-01 12:58:56
|
> Anyone tried to run subset of testcases within a test-suite in =
non-interactive mode? Any suggestions?
Some methods take a "test path" argument, you can put "RPTest" or =
"RPTest::testConnection" to specify which tests you want to run.
1) The "cppunittest" example shows you how to use a test path specified =
on the command line.
Look at cppunit/examples/cppunittest/CppUnitTestMain.cpp
2) The simpliest way to run a single test is to use a TextTestRunner, =
and to pass the test path to the method run() :
CPPUNIT_NS::Test* suite =3D =
CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
CPPUNIT_NS::TextTestRunner runner;
runner.addTest(suite);
runner.run("RPTest::testConnection");
But this is not very user-friendly, because it only prints dots as the =
tests are run. Anyway if you want to run only one test, this is not a =
problem.
3) A better way to run multiple tests is to use a =
BriefTestProgressListener : while the tests are running, it prints the =
name of the test and the result.
Here is an example, derived from cppunit/examples/simple/Main.cpp
CPPUNIT_NS::Test* suite =3D =
CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
CPPUNIT_NS::TestResult result;
CPPUNIT_NS::TestResultCollector collector;
result.addListener(&collector);
CPPUNIT_NS::BriefTestProgressListener brief;
result.addListener(&brief); =20
CPPUNIT_NS::TestRunner runner;
runner.addTest(suite);
runner.run(result, "RPTest");
CPPUNIT_NS::CompilerOutputter outputter(&collector, =
CPPUNIT_NS::stdCOut());
outputter.write();=20
Happy New Year.
Vincent.
|
|
From: <vin...@fr...> - 2005-12-23 10:04:28
|
> When I try to get name of a testcase it returns only the suite name.=20
>=20
> CPPUNIT_NS::Test *suite =3D =
CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
> CPPUNIT_NS::Test *childTest =3D suite->getChildTestAt( 0 );
> cout << "ChildTestName is: " << childTest->getName() << endl;
>=20
> CPPUNIT_NS::Test *childTest2 =3D suite->getChildTestAt( 1 );
> cout << "ChildTestName2 is: " << childTest2->getName() << endl;
Sorry, but for me it works as expected.
I use the lastest CVS version.
I have 2 tests :
class AssertMemoryTest : public CPPUNIT_NS::TestFixture { ... }
CPPUNIT_TEST_SUITE_REGISTRATION(AssertMemoryTest);
class AssertStringTest : public CPPUNIT_NS::TestFixture { ... }
CPPUNIT_TEST_SUITE_REGISTRATION(AssertStringTest);
When I run your code, I get the names of my 2 tests :
AssertMemoryTest=20
AssertStringTest
You may have made a mistake somewhere else.
First of all, try this just after calling makeTest():
int count =3D suite->getChildTestCount();
In my case, I get count =3D=3D 2.
And you ?
Good luck.
Vincent Rivi=E8re.
|