我有Junit测试执行带有参数的代码,
我想在断言失败的情况下使用另一个参数再次重试。
例如

@Test
public void test1() {
    boolean res = somelogic(3);
    assertTrue(res);
    // just if false I want to run again :
    boolean res = somelogic(4);
    assertTrue(res);
}


提前致谢

最佳答案

您可以利用Java支持short circuit evaluation的事实,并将测试编写为:

@Test
public void test1() {
    assertTrue(somelogic(3) || somelogic(4));
}


这样,如果somelogic(3)为false,则只有运行somelogic(4)才能确定断言的真实值。

08-06 10:07