java - 在 Maven 中使用 JUnit 类别运行测试时的性能损失
问题描述
我将一个项目从使用测试套件重构为使用 JUnit 类别注释。我注意到在使用类别时会出现相当显着的性能损失(慢 4 倍)。
背景:
- ~110 个测试类,包含 ~400 个测试方法
- old:这 110 个测试类是通过 11 个测试套件执行的(每个 maven 子模块都有一个测试套件)
- 新:这 110 个测试类现在由类别注释
FastTest
(在类级别) - 103 个测试方法被额外注释
SmokeTest
(每个测试类最多 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 插件只需要内省 Category 注释就需要相当多的时间。
是否有可能克服这种性能损失?注意:由于被测试的生产代码需要初始化/完成一个全局库(可以访问本机库,这不能在同一系统上并行完成),所以我很想使用连续执行(没有分叉,没有并行等)。 )
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>
冲浪插件版本:3.0.0-M5
解决方案
推荐阅读
- jquery - 在 ASP.NET Core 中的下拉值更改时从数据库中获取值
- c - 使用 pthread 库在线程之间进行同步
- python - 如何计算数据集的元素由列表组成
- python - 如何使用 pyodbc 在嵌套循环中调用不同的查询
- javascript - Vanilla JavaScript:如何搜索对象数组,键是数组
- python - 如何使用 Python 和来自 cricinfo 的 BeautifulSoup 提取玩家姓名
- list - 方案二进制列表到小数和
- javascript - 安装功能性Vue组件时“无法读取未定义的属性'props'”
- consul - 领事和特使整合
- docker - 任何 docker 命令都会出错:符号表错误