How to continue test case after failure

  • ctoomey

    ctoomey - 2006-10-11

    Is there way to have test cases continue after failures, rather than stopping at the first failure?  I.e., still print out the failure message, but continue the test.

    I've got some tests w/ loops containing CPPUNIT_ASSERT_MESSAGE.  I know I can hack something myself, but I'm hoping there's a cleaner way (different macros?) to go.


    • Code Guru

      Code Guru - 2006-10-12

      Perhaps you should break this up into separate test cases.  I assume the looping is to help automate different values used during the test case.  So rather than looping inside the test method, have a loop that creates separate test objects for each value.  Perhaps some pseudocode will help illustrate what I mean.

      Version 1:

      void testIntValue() {
        for (int i = 0; i < MAX; i++) {
          CPP_ASSERT_EQUALS(i, someObject.getIntValue());

      Version 2:

      class IntTester : public TestCase {
          IntTester(int i);
          void testIntValue();

      TestSuite suite() {
        TestSute suite = new TestSuite();

        for (int i = 0; i < MAX; i++) {

      I know this is not quite correct.  This is more or less my translation from how I would do it in Java with JUnit.  I hope it illustrates how you can refactor the for loop to create mutiple TestCase objects.  This allows you to run each test case independently rather than running them all at once and aborting on the first failure.

    • ctoomey

      ctoomey - 2006-10-13

      Thanks Layne, I see what you're saying but for what I'm doing that's more hassle than it's going to be worth.



Log in to post a comment.