I'm really struggling to work out how to pass command line arguments from main into my TestFixture - surely this must be easy to do?
Here's my main - I want to pass my one or more argvs into my
int main( int argc, char **argv)
//all I want is to get these argvs to my TextFixture!
// derive results filename from executable filename
std::string resultsFname = argv;
resultsFname += ".cppunitresults.txt";
// Create the event manager and test controller
// Add a listener that colllects test result
controller.addListener( &result );
// make a test runner, and add all registered tests
CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest( registry.makeTest() );
runner.run( controller, "" );
CppUnit::TextOutputter outputter(&result, resultsFile);
return result.wasSuccessful() ? 0 : 1;
Here's my TestFixture declaration:
class MyFixture:public CppUnit::TestFixture
I just don't see how to get the argvs into there - ideally for use in setUp(). Can someone help me out...I'm very confused?
The question remains just WHY you would want to have access to the command line args in setUp().
If you want to output something containing (parts of) the command line arguments as each test runs, _don't_ do it in setUp().
SetUp is strictly for setting up the test environment for each testcase; for logging and related stuff use a TestListener.
You create it as a Singleton, then call a method on it in main(), i.e. myTestListener::Instance().setCmdLineArgs(argc, argv),
which saves them to private members.
Then you implement the startTest() method of the TestListener (which gets called before each testcase, after you register the TestListener),
where you have access to the previously saved command line arguments and are able to do whatever it is you want to do.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.