java - 如何在 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
}
在不断言任何其他内容的情况下简单地使测试用例失败的最佳方法是什么?
解决方案
不要使用 if,而只是这样做:
assertEquals("Good Response!", responseString);
// perform additional assertions here
如果你只是想失败:
fail("I failed because...");
推荐阅读
- assembly - 使用 RTC 的 ASM 8086
- devexpress - 如何安装“HTML 属性编辑器”?
- java - 显示多维字符串数组的元素 [Java]
- postgresql - pg_dumpall 不提示密码
- yii2 - 如何添加自己的下拉菜单(从小部件)到CKEditor?
- asp.net - Visual Studio 发布的动态文件夹名称
- python-3.x - 从 Python 中的锚标记自动获取数据
- makefile - 如何修复 GNU/Make “打开的文件太多。停止。” 在不增加打开文件限制的情况下出错?
- java - 在 Java 中运行多个 replaceAll 语句
- c# - 我们如何实现字典
使用 getter & setter 属性