ama*_*ent 11 java junit maven-3 maven maven-surefire-plugin
为了管理/减少构建时间,我想确定哪些单元测试花费的时间最多 - 在并行测试环境中使用maven-surefire-plugin
.
我们使用JUnit
(4.10)进行单元测试.我们使用maven
(2.2.1 - 我们使用的一些插件尚不支持maven 3)作为我们的主要构建工具,并使用maven-surefire-plugin
(2.19)运行单元测试.
我们使用的是maven-surefire-plugin
在并行模式,其中两个单独的方法在平行和单元测试类运行并行运行-这是非常重要的,因为它显著降低建设单位测试时间.的maven-surefire-plugin
在构成.pom
如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<argLine>-Xmx2G -XX:MaxPermSize=1G -XX:-UseSplitVerifier</argLine>
<failIfNoTests>false</failIfNoTests>
<parallel>classesAndMethods</parallel>
<useUnlimitedThreads>true</useUnlimitedThreads>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
但是,其中一个含义是在控制台输出中,每个JUnit测试类所用的时间是该类中所有方法的总时间.
例如,如果测试类有10个单元测试方法,每个测试方法需要1秒才能运行,那么测试类需要大约1秒才能运行(每个方法并行运行),但输出类似于:
运行com.package.QuickParallelTest测试运行:10,失败:0,错误:0,跳过:0,已过去时间:10.0秒 - 在com.package.QuickParallelTest中
这使得很难在控制台输出与另一个测试类中区分10个单元测试方法,其中9个几乎立即运行,1个运行几乎需要10秒.在这种情况下,测试类需要大约10秒才能运行(因为一个慢速测试方法),但maven-surefire-plugin
控制台输出实际上是相同的:
运行com.package.SlowParallelTest测试运行:10,失败:0,错误:0,跳过:0,已过去时间:10.0秒 - 在com.package.SlowParallelTest
理想情况下,我希望花时间来指示测试类运行多长时间(并行),而不是单独运行方法所花费的总时间(就像单线程一样).
所以,我的问题是:
maven-surefire-plugin
吗?(我检查了SureFire JIRA,但找不到这样的东西.)编辑:
我试过玩一些额外的配置设置.奇怪的是,将以下内容添加到配置中.pom
似乎将控制台输出中经过的时间更改为运行测试类所花费的时间 - 但是,这(在我看来)这是违反直觉的,因为这些设置是默认设置:
<configuration>
...
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>
</configuration>
Run Code Online (Sandbox Code Playgroud)
A_D*_*teo 14
添加到Maven Surefire插件配置的reportFormat条目并将其值设置为plain
(而不是默认值brief
)将为每个方法提供经过的时间.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<argLine>-Xmx2G -XX:MaxPermSize=1G -XX:-UseSplitVerifier</argLine>
<failIfNoTests>false</failIfNoTests>
<parallel>classesAndMethods</parallel>
<useUnlimitedThreads>true</useUnlimitedThreads>
<reportFormat>plain</reportFormat>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
使用默认reportFormat(brief
)输出:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.sample.mocking.InternalServiceTestCase
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.241 sec - in com.sample.mocking.InternalServiceTestCase
Run Code Online (Sandbox Code Playgroud)
输出plain
值:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.sample.mocking.InternalServiceTestCase
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.187 sec - in com.sample.mocking.InternalServiceTestCase
test(com.sample.mocking.InternalServiceTestCase) Time elapsed: 0.005 sec
mockTest(com.sample.mocking.InternalServiceTestCase) Time elapsed: 0.17 sec
mockTestFailureTollerance(com.sample.mocking.InternalServiceTestCase) Time elapsed: 0.007 sec
mockProcessfile(com.sample.mocking.InternalServiceTestCase) Time elapsed: 0.003 sec
Run Code Online (Sandbox Code Playgroud)
此选项可为您提供有关测试和执行时间的更多详细信息.
归档时间: |
|
查看次数: |
3364 次 |
最近记录: |