Hi,
Pls explain, how to execute a single test from registry inspite of registering multiple test suites. How is the argv[] variable given to the main() passed to the test "getregistry().maketest();"
Kindly reply asap!!
Thank you,
Regards
Santhosh
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I couldn't find anything in the FAQs or documentation, so a bit of digging and experimentation I found a way to do it.
You can pass in an argument to the getRegistry() method, so here I pass in the command-line argument if one were provided:
int main(int argc, char* argv[])
{
// Get the top level suite from the registry
CPPUNIT_NS::Test *suite = CPPUNIT_NS::TestFactoryRegistry::getRegistry( argc == 2 ? argv[1] : "All Tests" ).makeTest();
...
This will create only the named test suite. How do you name a test suite? Like this:
So now in my project settings, I give the command-line argument "MyClass" and it only runs that one test. If I remove the cmd-line arg, all tests are run.
Bingo!
Cheers
- R
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
Pls explain, how to execute a single test from registry inspite of registering multiple test suites. How is the argv[] variable given to the main() passed to the test "getregistry().maketest();"
Kindly reply asap!!
Thank you,
Regards
Santhosh
I couldn't find anything in the FAQs or documentation, so a bit of digging and experimentation I found a way to do it.
You can pass in an argument to the getRegistry() method, so here I pass in the command-line argument if one were provided:
int main(int argc, char* argv[])
{
// Get the top level suite from the registry
CPPUNIT_NS::Test *suite = CPPUNIT_NS::TestFactoryRegistry::getRegistry( argc == 2 ? argv[1] : "All Tests" ).makeTest();
...
This will create only the named test suite. How do you name a test suite? Like this:
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MyClass_test, "MyClass" );
So now in my project settings, I give the command-line argument "MyClass" and it only runs that one test. If I remove the cmd-line arg, all tests are run.
Bingo!
Cheers
- R
OK, it turns out it's not quite as simple as that, but it's not too hard either.
You have to register the test both as a named test and as a default test, so your registration code looks like this:
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MyClass_test, "MyClass" );
CPPUNIT_TEST_SUITE_REGISTRATION( MyClass_test );
Why the named registration doesn't register it as default also I have no idea. Double the code, double the fun??!!
Hope that helps
- R