繁体   English   中英

如何在 JUnit 中显式或手动失败测试用例

[英]How to explicitly or manually fail a test case in JUnit

在我的 Java / RestAssured / TestNG 框架中,我想写一个具有以下结构的断言

if(responseString.equals("Good Response!")) {
  // perform additional assertions here
} else if(responseString.equals("Bad Response!")) {
  // just fail the test case right here and now
}

go 关于简单地使测试用例失败而不断言其他任何东西的最佳方法是什么?

不要使用 if,而只是这样做:

assertEquals("Good Response!", responseString);
// perform additional assertions here

如果你只是想失败:

fail("I failed because...");

Assert.assertEquals(true, false);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM