Unit testing slow with Cobertura
Asked Answered
T

1

8

I recently integrated Cobertura into my Ant build scripts and I am wondering if I did it correctly because it has significantly slowed down the time it takes to run the unit tests.

Here is a sample console output:

...
[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.
...

It seems fishy that after every test run Cobertura says:

[junit] Cobertura: Loaded information on 282 classes.
[junit] Cobertura: Saved information on 282 classes.
...

Here is my unit test task from my Ant build script:

    <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>

Does my setup and output seem correct? Is it normal for the unit tests to take 2.234 seconds when run alone and when run in the build script with Cobertura take 3 minutes?

Thigh answered 26/9, 2011 at 17:33 Comment(3)
I don't see what the problem is (besides using Ant :-P ), but this kind of delay is definitely not normal.Grew
I take it you have another preferred tool other than Ant? What would you recommend?Thigh
maven and gradle are both huge improvements over ant. adding cobertura to a maven project is trivial.Grew
Z
8

From 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.

(Emphasis is mine.)

Zendavesta answered 26/9, 2011 at 20:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.