繁体   English   中英

所有测试用例在 junit 中通过但 PIT 失败

[英]All test cases passed in junit but PIT is failing

在运行pit和jacoco时,所有测试用例都通过并且jacoco覆盖率很好,但是PIT突变测试失败并出现以下错误。

Build Failure
All tests did not pass without mutation when calculating line coverage. Mutation testing requires a green suite.

由于我所有的测试用例都通过了,我无法弄清楚为什么 PIT 测试失败了。 运行 PIT 测试时,我在控制台中看不到任何测试失败。

如果是这种情况,请建议如何查找 PIT 中哪个测试用例失败,如果不是,请告诉我 PIT 测试失败背后的原因。

当我将故障注入我的测试套件并运行 Pitest 时,它会清楚地向我显示哪些测试失败了。 即使没有启用“详细”日志记录。

我在我的pom.xml中配置了 Pitest,以便为我的测试添加一些配置以正常运行。 以下块可能位于<pluginManagement>部分或<profile>中:

            <plugin>
                <groupId>org.pitest</groupId>
                <artifactId>pitest-maven</artifactId>
                <version>1.8.0</version>
                <dependencies>
                    <dependency>
                        <groupId>org.pitest</groupId>
                        <artifactId>pitest-junit5-plugin</artifactId>
                        <version>0.16</version>
                    </dependency>
                </dependencies>
            </plugin>

现在我可以在命令行上运行mvn test-compile pitest:mutationCoverage来运行我的(有故障的)测试套件,而无需进行常规的单元测试。

在 Pitest 的控制台输出中,我可以看到哪些测试方法失败:

22:54:05 PIT >> INFO : Verbose logging is disabled. If you encounter a problem,
please enable it before reporting an issue.
22:54:06 PIT >> INFO : Incremental analysis reduced number of mutations by 0
22:54:06 PIT >> INFO : Created  69 mutation test units in pre scan
22:54:07 PIT >> INFO : Sending 85 test classes to minion
22:54:07 PIT >> INFO : Sent tests to minion
|22:54:17 PIT >> SEVERE : Description [testClass=com.myproject.core.MyTestClass,
  name=[engine:junit-jupiter]/[class:com.myproject.core.MyTestClass]/[method:testBrokenOne()]]
  did not pass without mutation.
/22:54:17 PIT >> SEVERE : Description [testClass=com.myproject.core.MyTestClass,
  name=[engine:junit-jupiter]/[class:com.myproject.core.MyTestClass]/[method:testMethodTwo()]]
  did not pass without mutation.
|22:54:19 PIT >> INFO : Calculated coverage in 13 seconds.
22:54:19 PIT >> SEVERE : Tests failing without mutation:
Description [testClass=com.myproject.core.MyTestClass,
  name=[engine:junit-jupiter]/[class:com.myproject.core.MyTestClass]/[method:testMethodOne()]]
Description [testClass=com.myproject.core.MyTestClass,
  name=[engine:junit-jupiter]/[class:com.myproject.core.MyTestClass]/[method:testMethodTwo()]]

(为可读性添加了换行符)

所以我看到MyTestClass.testMethodOne()MyTestClass.testMethodTwo()即使没有突变也无法运行。

当我在命令行上添加-Dverbose=true时,我发现测试框架的输出如下:

23:07:37 PIT >> INFO : MINION : org.opentest4j.AssertionFailedError: expected: <25> but was: <24>

如果需要,为了进一步缩小范围,您可能希望将每个测试方法限制为单个assert语句。 您可以添加日志记录(到控制台或文件)以检查测试的变量。

原因可能是您的常规测试得到的参数(也许您在命令行或 pom 中指定了某些属性?),但在 Pitest 启动时却没有。 我自己最近才了解到,在某些情况下,Pitest 会产生新的 jvm 实例,这些实例需要通过<jvmArgs>获取参数。

暂无
暂无

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

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