Hi all ,
I met problem like this:
in VC++7.0 enviroment ,add post buid , I want to show all the failed assert result ,but I can only get the first assert failed result , and program stop .could you tell me how to get all the failed assert result in the end ,then stop:
My code is like this:
int main( int argc, char* argv[] ) {
bool CppunitTest = (argc > 1) &&
(std::string("-cppunittest") == argv[1]);
we're facing the same problem. It seems, that cppunit throws an exception, when an assertion failed. So the function exits and the remaining assertions are not covered. I'll post my resolution when found.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That's the point- after one assertion fails, the rest of the function is semantically invalid.
I don't remember who said it, but one of the testing luminaries tells us to put only one assertion in each test. Doing that, you'll get the behavior you're looking for.
Think about this like "test only one thing at a time." Your function should be called "testSomething", not "testSomethingAndSomethingElseAndMaybeAThirdThing".
I've personally found my tests became much more expressive when I started doing one assertion per test case. It "forces" you to use fixtures more for your setup and tear-down, but that's actually a good thing IMO. E.g. encapsulate your setup and tear-down functionality into the class's setUp and tearDown routines, and then your tests become really easy to understand since they do one thing and do it well.
Good luck,
-tom!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all ,
I met problem like this:
in VC++7.0 enviroment ,add post buid , I want to show all the failed assert result ,but I can only get the first assert failed result , and program stop .could you tell me how to get all the failed assert result in the end ,then stop:
My code is like this:
int main( int argc, char* argv[] ) {
bool CppunitTest = (argc > 1) &&
(std::string("-cppunittest") == argv[1]);
CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry("SCppunitTest");
runner.addTest( registry.makeTest() );
if ( CppunitTest )
{ runner.setOutputter( CppUnit::CompilerOutputter::defaultOutputter(&runner.result(),
std::cerr ) );
}
bool wasSucessful = runner.run( "", !CppunitTest);
return wasSucessful ? 0 : 1;
Hi,
we're facing the same problem. It seems, that cppunit throws an exception, when an assertion failed. So the function exits and the remaining assertions are not covered. I'll post my resolution when found.
That's the point- after one assertion fails, the rest of the function is semantically invalid.
I don't remember who said it, but one of the testing luminaries tells us to put only one assertion in each test. Doing that, you'll get the behavior you're looking for.
Think about this like "test only one thing at a time." Your function should be called "testSomething", not "testSomethingAndSomethingElseAndMaybeAThirdThing".
I've personally found my tests became much more expressive when I started doing one assertion per test case. It "forces" you to use fixtures more for your setup and tear-down, but that's actually a good thing IMO. E.g. encapsulate your setup and tear-down functionality into the class's setUp and tearDown routines, and then your tests become really easy to understand since they do one thing and do it well.
Good luck,
-tom!