java - Intellij 关于 SoftAssertion 后空检查的警告
问题描述
我有一些测试,其中我创建了多个验证器函数,这些函数在每个测试用例上运行多个断言。我已经将这些验证器设置为将其实例SoftAssertions
传递给每个验证器,并assertAll()
在所有验证器函数运行后调用。对于我的一个验证器,我有以下断言:
TestArtifact artifactA = testArtifacts.getArtifactA();
softAsserts.assertThat(artifactA)
.as("TestArtifactA should not be null")
.isNotNull();
if (artifactA != null) {
softAsserts.assertThat(artifactA.getTimestamp())
.isEqualTo(expectedTimestamp);
// additional assertions omitted
}
我的理解是,由于SoftAssertions
只会在调用函数时测试用例失败assertAll()
,所以上面的空检查是必要的,以防上面SoftAssertion
的错误。但是,在 Intellij 中,我在 if 语句中收到一条警告消息,说:
Condition 'artifactA != null' is always 'true'
我已经确认,如果isNotNull()
软断言被删除,警告就会消失。这个警告只是来自 Intellij 的误报吗?或者我是否遗漏了一些SoftAssertions
实际上使断言后的空检查变得不必要的东西?
解决方案
推荐阅读
- keras - Keras Lambda 层输出不是“符号张量”
- excel - 当A列的值相似时,它将通过创建另一个新表来根据A列对b列求和
- libc++ - deb http://llvm.org/apt/stretch/llvm-toolchain-stretch-7 main 中的 libc++fs.a 文件是否损坏
- c# - c#中的减法?
- ms-access - 如何防止用户在 MS ACCESS 2013 中删除/编辑或添加子表单上的记录
- javascript - 如何在全日历中设置 Themename?
- mysql - 从特定列表中选择随机数
- javascript - 在Angular 7中并排组合两个数组
- python - 如何在 django 中使用模型进行查询
- java - 无法渲染 jsp 页面