Java Build and Test Tools
We have experience in build and testing of Java applications and we would like to share this experience with you.
If you need help with your build and test infrastructure needs, we can help you with the following:
- Build scripts for the Ant Build Tool
- CVS extract / check in within Ant scripts
- Generate Javadoc with Ant (With some tips to remove unwanted Javadoc)
- Invocation of JUnit tests within Ant build scripts
- Source code coverage using Emma within Ant / JUnit tests
- Instrumenting test or product code binaries via AspectJ using Ant scripts
- Obfuscating your jars with yGuard
- Packaging your Java Application as a Windows Executable using JExecutable - Java Exe Maker .
- Best practices help in implementing JDBC / Database tests with plain old JUnit and Ant
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.
Ant Build Tool
Ant is a widely popular build tool for Java applications. It can have uses besides builds as well. Ant is cross platform by design. Ant build scripts are written in XML. These XML files are interpreted by Ant which
itself is written in Java. Using Ant you can typically build Java classes, create jars, package these jars as destributable packages or installers.
Typical tasks in an Ant build file includes details like extract source code from source code control system. Ant can interact with popular systems such as CVS, SVN, ClearCase, Perforce and more. Ant is able to use
operating system commands and is not limited to Ant command syntax.
Ant can compile your java source code and create output jars with additional artifacts such as properties files, text files, images that goes into your jar. Ant has support to easily maintain build numbers. Each
build can increment a build number and check in incremented version into the source code control system.
Ant has support to generate Javadocs based on your Java source code.
JUnit Test Tool
JUnit is a popular Java unit testing framework. JUnit allows the developers write small unit test functions. Various tools and IDEs such as Ant, Eclipse has support to run these tests and get a visually appealing
HTML reports of the test status.
Code Coverage with Emma
Emma is a free code coverage tool for Java applications. It comes with an Ant task which allowsit to be easily integrated in Ant scripts. Emma instruments your code at compile time. At runtime you set a JVM flag to
turn coverage on and off. Emma can generate reports as text, html or xml. HTML reports are easy to grasp and it can help you understand your test coverage in a short time.
AspectJ - Tracing with aspects and more
AspectJ is a Aspect Oriented Programming compiler from eclipse.org for Aspects and Java source code. We typically use it to inject tracing code to help troubleshoot problems. It helps in investigating test failures
and it also helps customer support in the field. If used in the field in production code, AspectJ has a runtime component - a jar file that needs to be shipped with the application.
yGuard - Obfuscate and Shrink Jars
yGuard is a byte code obfuscator which makes the code impossible to read after decompilation. yGuard protects your intellectual property against decompilation. Bestcode can hep you get started with yGuard to
obfuscate your jars. yGuard integrates well with Ant through an Ant task.
You may contact us with your build and test problems to get a free quote. firstname.lastname@example.org