是否有可能使黄瓜测试失败?

Is it possible to make cucumber test fail?

我下面的这段代码比较了两个列表。 在我的步骤中,我使用 if 语句检查 destinationList 是否为空,如果是,则测试正确并且应该继续执行黄瓜步骤。

但是,如果到达 else 语句,是否有办法导致黄瓜测试失败? `

if (destinationList.isEmpty()) {
    System.out.println("This report is correct");

} else {
     System.out.println("This report is incorrect.");
     System.out.println("This list conatains the expected values of the report and their locations:");
     System.out.println("expected = "+sourceList);
     System.out.println("This list contains the actual value from this report and their locations:");
     System.out.println("actual = "+destinationList);
}

您使用 JUnit 作为您的测试框架吗?如果是,则使用

fail("Reason of fail")

这是来自class Assert 的静态方法 http://junit.sourceforge.net/javadoc/org/junit/Assert.html

我找到了答案。 我首先尝试了 assert fail,但没有用。

我在 else 语句的底部包含了正确的语法 Assert.fail();