In the Java Programming language we use a discipline for testing called Test Driven Development (TDD). It’s the way we Develop Java Applications. Before we actually start writing code we first create a JUnittest case. This is just our functional code but enhanced with assertions that makes sure that the code will work as expected.
This may seem overkill but actually it’s a big timesaver because it’s automated. Once we know what our class should do we start coding it as a Test Case. In order to enable this, we add the Junit Jar in our Classpath and start coding.
Real world advantages
Everyone who ever did Application Support will understand the advantages. When something is wrong and you’re job is to figure out what it is you definitely profit from knowing which parts of the Application are definitely good and can be excluded from testing manually. Also deployment is much easier and more professional when you can deliver the project together with a professional looking test report.
After the Java development is done we extract the functional code and start working on the build script. This can either be done with Apache Ant or Apache Maven. The latter has the advantage of being dependancy aware, which is a big advantage because it will automatically download the required dependancies during the building process.
In the building scripts (whichever we use, the Junit tests are all included and executed during building. With every build a nice looking test report is generated which shows us if everything is still working as expected.
For big projects which are continuously updated there is Continuous integration. The project is buid over and over again. This is done by a Web Application which resides on a Servlet Container or Web Application Server. The Web Application is usually Apache Jenkins. It’s widely used in the larger Open Source projects. You can see Jenkins in action at https://builds.apache.org/. Open the link and choose a project. You can also choose to monitor the projects life.
Java Junit testing makes it easier for Java Developers to produce high quality and stable code. It also saves time and efforts.