使用 trompeloeil 单元测试框架和 TDD:https ://github.com/rollbear/trompeloeil/blob/master/docs/reference.md
给定以下测试用例
Testcase 1:
Expectation_A: a() is called
Expectation_B: b() is called
Testcase 2:
Expectation_A: a() is called
Expectation_C: c() is called
可以使用 TDD 轻松编写它们:
WHEN("")
{
REQUIRE_CALL(*myMock, a());
AND_WHEN("")
{
REQUIRE_CALL(*myMock, b());
THEN("")
{
objectUnderTest.call();
}
}
AND_WHEN("")
{
REQUIRE_CALL(*myMock, c());
THEN("")
{
objectUnderTest.call();
}
}
}
但是,我不知道如何处理这种情况,当两个测试用例中的一系列期望相同时,在两个序列中一个期望/参数化区域不同之后:
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
我知道如何使用 TDD 编写它们的唯一方法是:
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();
}
}
}
有没有办法在测试用例不同后重新加入测试用例的执行流程,或者我真的必须复制和粘贴,只要 2 个测试用例不同?