Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 608
Alex B Avatar asked Sep 23 '08 19:09

Alex B


People also ask

Which of the following is correct about test runner in JUnit?

Q 17 - Which of the following is correct about Test Runner in JUnit? A - Test runner is used for executing the test cases.

Why is JUnit so slow?

The problem is that JUnit (or something in our tests or test runner) is doing a DNS lookup on the machine's hostname. That lookup should be really fast, but if you're connected to a VPN it may search the remote DNS server which takes time and makes the tests take much longer than they should.

Which annotation is often used for tests that are known to fail and would break a continuous integration build?

@After annotation is used on a method containing java code to run after each test case. These methods will run even if any exceptions are thrown in the test case or in the case of assertion failures.


2 Answers

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.

like image 97
bsanders Avatar answered Oct 05 '22 09:10

bsanders


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.

like image 30
Risser Avatar answered Oct 05 '22 09:10

Risser