<-- Back to Current Category
A Build and Test System with Ant, JUnit, Emma Code Coverage
By: David Dale, Sat Jan 24th, 2009
Ant build tool is very popular in Java development. Ant scripts are developed in XML with familiar syntax that is consumable by tools and they are interpreted by Ant which is written in Java and is portable accross platforms. These gave enough advantages to Ant over make files, jam and other build tools to be adopted across the industry.
Ant has tasks not only to compile source code, but also to run build and test related tasks. These are typically details like creating jars, zips, javadoc, running junit tests, interacting with source code control systems like CVS, SVN, ClearCase, Perforce etc.
To put together your entire build and test story, you can start with Ant. But you cannot stop there. Getting source code from CVS, and compiling it is just the first chapter.
Most modern software has cross cutting concerns such that code injection across the board is much easier to maintain and implement compared to typing the code for it. For example you may consider Aspect Oriented tracing facilities for your software. Using AspectJ you can easily inject tracing code into your binaries using Ant AspectJ task. This approach keeps your code clean from tracing details and it makes it possible to quickly compile trace and no-trace versions of your source code. Extensive trace makes it easy to troubleshoot test failures and support products on the field.
Complexity of modern software and dependencies between third party components make it is impossible ship without proper testing. It would be a best practice for your development team to run sanity tests before every check in of source code as well. The cost of uncaught defects increases exponentially with the production phase they are found in. It is cheapest to catch defects with unit testing at development time. It can be thousands of times more expensive if they are found by the customer. To tackle testing infrastructure we have JUnit test framework. Ant makes it easy to integrate JUnit tests into an Ant script. There are also tasks to generate HTML reports for JUnit test runs. These makes Ant-JUnit combo an excellent tool to hunt for defects and view status.
A challenge in testing is to find out what needs to be tested. When you are not intimately familiar with all aspects of the product, it may be hard to see what is covered and what is not covered in the tests. Emma, a code coverage tool, can be integrated with Ant and JUnit to provide code coverage analysis. Emma can provide HTML reports that can clearly show which parts of the source code are not covered by the tests. Notice that code that is shown to have executed does not mean that it is properly tested. In other words, merely executing source code does not guarantee that it is tested, but code that is not executed at all is guaranteed to be not tested.
After your build and tests are complete, the next challenge is to report the results in a consumable way to the rest of the team and others who are interested. This can typically be achieved by running a web server to display results. Keep in mind, sometimes it helps to have some smarts in the web servers to interpret the results and show summaries or transform it to be more usable. For these tasks, PHP or JSP, or ASP can be used. There are easy to setup servers out there such as WAMP or XAMPP that you can get going quickly with PHP.
If you need help with your build and testing needs we, at bestcode.com, can help you using the Build and Test Tools such as Ant, JUnit, AspectJ, Emma and others mentioned above.