Ant 用Cobertura进行单元测试
我最近将Cobertura集成到我的Ant构建脚本中,我想知道我是否做得正确,因为它大大降低了运行单元测试所需的时间 以下是控制台输出示例:Ant 用Cobertura进行单元测试,ant,junit,cobertura,Ant,Junit,Cobertura,我最近将Cobertura集成到我的Ant构建脚本中,我想知道我是否做得正确,因为它大大降低了运行单元测试所需的时间 以下是控制台输出示例: ... [junit] Running gov.nyc.doitt.gis.webmap.strategy.markup.ViewportDeterminingMarkupStrategyTest [junit] Tests run: 5, Failures: 0, Errors: 0, Time elapsed: 0.38 sec [junit] Flu
...
[junit] Running gov.nyc.doitt.gis.webmap.strategy.markup.ViewportDeterminingMarkupStrategyTest
[junit] Tests run: 5, Failures: 0, Errors: 0, Time elapsed: 0.38 sec
[junit] Flushing results...
[junit] Flushing results done
[junit] Cobertura: Loaded information on 282 classes.
[junit] Cobertura: Saved information on 282 classes.
[junit] Running gov.nyc.doitt.gis.webmap.strategy.markup.VisibleFeatureTypesMarkupInfoTest
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.434 sec
[junit] Flushing results...
[junit] Flushing results done
[junit] Cobertura: Loaded information on 282 classes.
[junit] Cobertura: Saved information on 282 classes.
[junit] Running gov.nyc.doitt.gis.webmap.strategy.markup.basemap.BasemapByViewportStrategyTest
[junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 2.016 sec
[junit] Flushing results...
[junit] Flushing results done
[junit] Cobertura: Loaded information on 282 classes.
[junit] Cobertura: Saved information on 282 classes.
[junit] Running gov.nyc.doitt.gis.webmap.strategy.markup.basemap.BasemapByZoomLevelAndCenterPointStrategyTest
[junit] Tests run: 4, Failures: 0, Errors: 0, Time elapsed: 1.853 sec
[junit] Flushing results...
[junit] Flushing results done
[junit] Cobertura: Loaded information on 282 classes.
[junit] Cobertura: Saved information on 282 classes.
...
每次测试运行后,Cobertura说:
[junit] Cobertura: Loaded information on 282 classes.
[junit] Cobertura: Saved information on 282 classes.
...
以下是我的Ant构建脚本中的单元测试任务:
<target name="unit-test" depends="compile-unit-test">
<delete dir="${reports.xml.dir}" />
<delete dir="${reports.html.dir}" />
<mkdir dir="${reports.xml.dir}" />
<mkdir dir="${reports.html.dir}" />
<junit fork="yes" dir="${basedir}" failureProperty="test.failed" printsummary="on">
<!--
Note the classpath order: instrumented classes are before the
original (uninstrumented) classes. This is important.
-->
<classpath location="${instrumented.dir}" />
<classpath refid="test-classpath" />
<formatter type="xml" />
<test name="${testcase}" todir="${reports.xml.dir}" if="testcase" />
<batchtest todir="${reports.xml.dir}" unless="testcase">
<fileset dir="TestSource">
<include name="**/*Test.java" />
<exclude name="**/XmlTest.java" />
<exclude name="**/ElectedOfficialTest.java" />
<exclude name="**/ThematicManagerFixturesTest.java" />
</fileset>
</batchtest>
</junit>
</target>
我的设置和输出是否正确?单独运行时,单元测试需要2.234秒,使用Cobertura在构建脚本中运行时需要3分钟,这正常吗?来自:
出于同样的原因,如果您使用的是Ant1.6.2或更高版本,那么
可能希望设置forkmode=“once”这将导致只创建一个JVM
已为所有JUnit测试启动,并将减少
Cobertura每次启动JVM时读取/写入覆盖率数据文件
开始/停止
(重点是我的。)我看不出问题出在哪里(除了使用Ant:-p),但这种延迟肯定不正常。我想你除了Ant还有其他更喜欢的工具吗?你有什么建议吗?maven和gradle都是对ant的巨大改进。将cobertura添加到maven项目是很简单的。