Alex B
Alex B

Reputation: 24936

Ant Junit tests are running much slower via ant than via IDE - what to look at?

I am running my junit tests via ant and they are running substantially slower than via the IDE. My ant call is:

    <junit fork="yes" forkmode="once" printsummary="off">
        <classpath refid="test.classpath"/>
        <formatter type="brief" usefile="false"/>
        <batchtest todir="${test.results.dir}/xml">
            <formatter type="xml"/>
            <fileset dir="src" includes="**/*Test.java" />
        </batchtest>
    </junit>

The same test that runs in near instantaneously in my IDE (0.067s) takes 4.632s when run through Ant. In the past, I've been able to speed up test problems like this by using the junit fork parameter but this doesn't seem to be helping in this case. What properties or parameters can I look at to speed up these tests?

More info:

I am using the reported time from the IDE vs. the time that the junit task outputs. This is not the sum total time reported at the end of the ant run.

So, bizarrely, this problem has resolved itself. What could have caused this problem? The system runs on a local disk so that is not the problem.

Upvotes: 9

Views: 4653

Answers (7)

Chin
Chin

Reputation: 20675

For me, adding forkmode="once" for the <junit> element and adding usefile="false" for the <formatter> element makes the tests run much faster. Also remove the formatters that you don't need.

Upvotes: 0

Kristof Neirynck
Kristof Neirynck

Reputation: 4162

Try setting fork, forkmode and threads to these values:

<junit fork="yes" forkmode="perTest" printsummary="off" threads="4">
    <classpath refid="test.classpath"/>
    <formatter type="brief" usefile="false"/>
    <batchtest todir="${test.results.dir}/xml">
        <formatter type="xml"/>
        <fileset dir="src" includes="**/*Test.java" />
    </batchtest>
</junit>

Also see https://ant.apache.org/manual/Tasks/junit.html

Upvotes: 0

marcospereira
marcospereira

Reputation: 12214

Maybe you are seeing that because Eclipse do incremental compiling and Ant don't. Can you confirm that this time is wasted only in the test target?

Upvotes: 1

Risser
Risser

Reputation: 71

I'm guessing it's because your antscript is outputing results to XML files, whereas the IDE is keeping those in memory. It takes longer to write a file than to not write a file.

todir="${test.results.dir}/xml"

That's the part of the <batchtest> call that tells it to stick the results into that directory. It looks like leaving it off just tells it to stick the results in the "current directory", whatever that is. At first glance I didn't see anything to turn it all the way off.

Upvotes: 4

James Van Huis
James Van Huis

Reputation: 5561

For the record, I found my problem. We have been using a code obfuscator for this project, and the string encryption portion of that obfuscator was set to "maximum". This slowed down any operation where strings were present.

Turning down the string encryption to a faster mode fixed the problem.

Upvotes: 0

bsanders
bsanders

Reputation: 111

Here's a blind guess: try increasing the maximum heap size available to the forked VM by using a nested <jvmarg> tag to set the -Xmx option.

Upvotes: 4

Eric Asberry
Eric Asberry

Reputation: 612

Difficult to tell with that information. First thing I would do is look at the test results and determine if all the individual tests are running uniformly slower or if it can be narrowed down to a certain subset of test cases.

(The zero'th thing I would do is make sure that my ant task is using the same JVM as Eclipse and that the classpath dependencies and imported JARs are really and truly identical)

Upvotes: 1

Related Questions