首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >所有测试用例都在junit中通过,但是PIT失败了。

所有测试用例都在junit中通过,但是PIT失败了。
EN

Stack Overflow用户
提问于 2022-06-14 18:21:34
回答 1查看 362关注 0票数 -1

在运行pit和jacoco时,所有的测试用例都通过了,并且测试覆盖范围很好,但是坑突变测试失败了,误差在以下。

代码语言:javascript
复制
Build Failure
All tests did not pass without mutation when calculating line coverage. Mutation testing requires a green suite.

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

如果是这样的话,请建议如何找出哪一个测试用例失败了,如果不是,请让我知道什么是坑测试失败的原因。

EN

回答 1

Stack Overflow用户

发布于 2022-06-15 21:14:20

当我将错误注入测试套件并运行Pitest时,它将清楚地显示哪些测试失败。即使没有启用“冗长”的日志记录。

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

代码语言:javascript
复制
            <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的控制台输出中,我可以看到哪些测试方法失败了:

代码语言:javascript
复制
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时,我发现测试框架的输出如下:

代码语言:javascript
复制
23:07:37 PIT >> INFO : MINION : org.opentest4j.AssertionFailedError: expected: <25> but was: <24>

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

原因可能是一个参数(可能您在命令行或pom中指定了一些属性?)你的常规测试结果,但不是皮特斯特开始的时候。我自己最近才了解到,Pitest生成了新的jvm实例,在某些情况下需要获得通过<jvmArgs>传输的参数。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72621734

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档