How do I run a single test with UnitTest++ ?
+2
A:
try this as your main() for unittest (I actually put this in a file and added that to the unittest library, so that when linking to the libarray, the executable automatically uses this main(). very convenient.)
int main( int argc, char** argv )
{
if( argc > 1 )
{
//if ifrst arg is "suite", we sarch for suite names instead of test names
const bool bSuite = strcmp( "suite", argv[ 1 ] ) == 0;
//walk list of all tests, add those with a name that
//matches one of the arguments to a new TestList
const TestList& allTests( Test::GetTestList() );
TestList selectedTests;
Test* p = allTests.GetHead();
while( p )
{
for( int i = 1 ; i < argc ; ++i )
if( strcmp( bSuite ? p->m_details.suiteName
: p->m_details.testName, argv[ i ] ) == 0 )
selectedTests.Add( p );
p = p->next;
}
//run selected test(s) only
TestReporterStdout reporter;
TestRunner runner( reporter );
return runner.RunTestsIf( selectedTests, 0, True(), 0 );
}
else
{
return RunAllTests();
}
}
invoke with arguments to run a single test:
> myexe MyTestName
or single suite
> myexe suite MySuite
stijn
2010-08-23 10:14:48
This is what I was looking for. Thanks a lot. I will give it a try straight away.
Arno
2010-08-23 10:42:27
Works perfect ! Thanks a lot !
Arno
2010-08-23 10:48:35