如何在 Junit 中使测试用例失败?

How to make a test case as fail in Junit?

当我在脚本中使用 fail()[Junit] 时,脚本会停止 运行ning 并跳过后续步骤。

 In TestNG, We can do that using "org.testng.Assert.fail("");" .

我的要求是继续运行下一个场景,即使我之前的案例失败了。

请帮帮我。

您需要使用软断言。像这样

public static void verifyFalse(boolean condition) {
    try {
        assertFalse(condition);
} catch(Throwable e) {
        e.printStackTrace();
        throw new YourException("your message");
}

JUnit 具有 ErrorCollector rule 软断言。

public class ATest {
  @Rule
  public final ErrorCollector collector = new ErrorCollector();

  @Test
  public void test() {
    //do some stuff
    collector.addError(new Throwable("something went wrong"));
    //do other stuff
  }
}