关于 SoftAssertion 后空检查的 Intellij 警告

问题描述

我有一些测试,其中我创建了多个验证器函数,这些函数在每个测试用例上运行多个断言。我已将这些验证器设置为具有传递给每个验证器的 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内容,这实际上使断言后的空检查变得不必要?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)