How can we find the junit tests in our suite that take the longest amount of time to run? The default output of the junitreport ant task is helpful, but our suite has thousands of tests organized into many smaller suites, so it gets tedious, and the worst offenders are always changing.
We use luntbuild but ideally it would be something we could just run from ant.
Still, it seems as though a 10 second short-term attention span is more or less hard-wired into the human brain. Thus, a unit test suite used for TDD should run in less than 10 seconds. If it's slower, you'll be less productive because you'll constantly lose focus.
Some developers will be happy to run their extensive test suite in three minutes, while others want to go the more radical route and keep it under 60 seconds.
Run all your unit tests as often as possible, ideally every time the code is changed. Make sure all your unit tests always run at 100%. Frequent testing gives you confidence that your changes didn't break anything and generally lowers the stress of programming in the dark.
JUnitReport works on the xml files produced by the JUnit task. You could write a task that would read the test durations out of the same xml files (TEST-*.xml). But you can also take a shortcut and just read the summary file created by JUnitReport (TESTS-TestSuites.xml) which has all the information in the single file.
A quick way to do this is to use a bit of xsl to just show the slowest tests:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:text> </xsl:text>
<xsl:for-each select="testsuites/testsuite">
<xsl:sort select="@time" data-type="number" order="descending" />
<xsl:value-of select="@name"/> : <xsl:value-of select="@time"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
To run from Ant you do this:
<target name="show.slow.tests">
<xslt in="target/tests-results/TESTS-TestSuites.xml" out="target/slow.txt" style="slow.xsl"/>
</target>
Then you can just look at the first X lines to find the X slowest tests:
jfredrick$ head target/slow.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With