gpt4 book ai didi

ant - 使用 Cobertura 进行单元测试很慢

转载 作者:行者123 更新时间:2023-12-04 07:43:09 25 4
gpt4 key购买 nike

我最近将 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] 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 分钟是否正常?

最佳答案

来自 cobertura-anttask reference :

For this same reason, if you're using ant 1.6.2 or higher then you might want to set forkmode="once" This will cause only one JVM to be started for all your JUnit tests, and will reduce the overhead of Cobertura reading/writing the coverage data file each time a JVM starts/stops.



(重点是我的。)

关于ant - 使用 Cobertura 进行单元测试很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7558904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com