如何解决在Maven中使用JUnit类别运行测试时性能下降
我将项目从使用测试套件重构为使用JUnit类别注释。使用类别时,我注意到了相当可观的性能损失(慢4倍)。
背景:
- 〜110个测试类,包含约400个测试方法
- old:这110个测试类是通过11个TestSuite执行的(每个maven子模块都有一个测试套件)
- 新功能:这110个测试类现在由类别
FastTest
注释(在类级别) - 另外
SmokeTest
注释了103种测试方法(每个测试类最多1个测试用例) - SmokeTest接口是FastTest的派生
开始分类测试:mvn test -P fast-tests
rsp。 mvn test -P smoke-tests
(请参阅下面的pom.xml)。
Maven输出
Old (suites) New (FastTest) new (SmokeTest)
Total time: 02:04 min 07:55 min 06:33 min
Time elapsed (summed up) 95.638 s 102.925 s 51.484
使用类别的运行持续时间将近4倍(在执行相同数量的测试时)。执行冒烟测试(103个测试用例)的时间几乎与执行所有400个测试用例的时间一样长。
从报告的Total time
到总结的Time elapsed
显然也是很大的区别。后者似乎只是测试方法中测得的时间,而没有额外的开销(启动JVM等)。
看来,仅通过对类别注释进行内省,surfire插件就需要大量时间。
是否有可能克服这种性能损失?注意:由于要测试的生产性代码需要初始化/完成全局库(可以访问本机库,因此无法在同一系统上并行执行),因此我很难使用成功执行(无派生,无并行等)。 )
Pom.xml(部分)
<profile>
<id>smoke-tests</id>
<properties>
<test.includedGroups>
ch.ergonomics.junit.category.SmokeTest
</test.includedGroups>
<test.excludedGroups></test.excludedGroups>
</properties>
</profile>
<profile>
<id>fast-tests</id>
<properties>
<test.includedGroups>
ch.ergonomics.junit.category.FastTest
</test.includedGroups>
<test.excludedGroups></test.excludedGroups>
</properties>
</profile>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<groups>${test.includedGroups}</groups>
<excludedGroups>${test.excludedGroups}</excludedGroups>
<useSystemClassLoader>false</useSystemClassLoader>
<threadCount>1</threadCount>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
</configuration>
</plugin>
surfire插件版本:3.0.0-M5
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。