1

Using the trompeloeil unit test framework and TDD: https://github.com/rollbear/trompeloeil/blob/master/docs/reference.md

Given the following test cases

Testcase 1:
  Expectation_A: a() is called
  Expectation_B: b() is called

Testcase 2:
  Expectation_A: a() is called
  Expectation_C: c() is called

One can easily write them using TDD:

WHEN("")
{
    REQUIRE_CALL(*myMock, a());

    AND_WHEN("")
    {
        REQUIRE_CALL(*myMock, b());
        THEN("")
        {
            objectUnderTest.call();
        }
    }

    AND_WHEN("")
    {
        REQUIRE_CALL(*myMock, c());
        THEN("")
        {
            objectUnderTest.call();
        }
    }
}

However, I don't know to handle the case, when a sequence of expectations is the same in both testcases, after one expectation/a parametrized area was different in the both sequences:

Testcase 1:
  Expectation_A: a() is called
  Expectation_B: b() is called
  Expectation_D1: d1() is called
  Expectation_D2: d2() is called
  Expectation_D3: d3() is called

Testcase 2:
  Expectation_A: a() is called
  Expectation_C: c() is called   // differs
  Expectation_D1: d1() is called // same as TC1 from here on
  Expectation_D2: d2() is called
  Expectation_D3: d3() is called

The only way I know how to write them using TDD is:

WHEN("")
{
    REQUIRE_CALL(*myMock, a());

    AND_WHEN("")
    {
        REQUIRE_CALL(*myMock, b());
        REQUIRE_CALL(*myMock, d1());
        REQUIRE_CALL(*myMock, d2());
        REQUIRE_CALL(*myMock, d3());
        THEN("")
        {
            objectUnderTest.call();
        }
    }

    AND_WHEN("")
    {
        REQUIRE_CALL(*myMock, c());
        REQUIRE_CALL(*myMock, d1());
        REQUIRE_CALL(*myMock, d2());
        REQUIRE_CALL(*myMock, d3());
        THEN("")
        {
            objectUnderTest.call();
        }
    }
}

Is there a way to rejoin the execution flow for testcases after they have differed, or do I really have to copy & paste, as soon as the 2 testcases differ?

arved
  • 4,401
  • 4
  • 30
  • 53
Joki
  • 9
  • 1
  • 2

0 Answers0