Advanced Java Testing 2.0


The Roots

Do you remember the feeling...coding, it gets more and more complex, you start to fix here and there and finally run into a dead end? Todays software development methodologies and tools allow far more sophisticated software development. Smalltalk has been an incredible source for ideas and tools, but is has never been widely used. Java is just starting to catch up. My hope is that I can help making Java programming faster and more reliable with the tools presented here.

When I found Kent Beck's and Erich Gamma's JUnit testing framework, I worked with it and decided to integrate it into Together, the most advanced UML modeling tool I could find up to now. This integration is called XPTest and consists of a module and several patterns. It relies on JUnitX, an extension of JUnit which supports access to private and protected classes, methods and variables. BTW, JUnit has its roots in a testing framework Kent Beck implemented in Smalltalk.

In December 2000 JUnitX and XPTest won the first prize in the Together Custom Building Block contest. In 2001 the TogetherLabs joined the development. Today, JUnit, JUnitX and XPtest are 3rd party modules contained in the Together distribution.


How do you want to develop tomorrow?

This article shows you how to develop Java applications fast and reliably while avoiding dead ends. You will see how you can combine Java, UML, Together, JUnitX, XPTest, Ant and features of Extreme Programming for successful software development. Java Beginners as well as experienced programmers will find valuable tips here to use in their daily work. If you want to use JUnitX without XPTest, just paste code generated by Together from Appendix B from time to time.

This tutorial intentionally does not discuss architecture, design or software methodologies / project management for big projects and teams. First of all, it shall help you to improve your development efficiency and then to improve the output of your team and your project.


The steps we'll go

Step 1
Write the story
What do we want to achieve? Let's implement an URL parser as example for an application requiring systematic testing to get stable.
Step 2
Analysis and Tasks
What does the requirements mean to us and how can we break them down into steps we are able to take.
Step 3
Initial design
How should the solution look like? After analyzing the requirements we decide which classes to create.
Step 4
Project setup
In order to write our ideas down in UML we need to set up an initial project. Using that environment, the initial UML diagrams will be created.
Step 5
Refined design
How should the classes work together, which methods should they have? This step results in a compilable skeleton of the solution.
Step 6
Build
Catching the typos and syntax errors requires a build environment. Several solution are presented including a short subtutorial on how to use and integrate Ant, a pure-java alternative to make.
Step 7
Unit tests
Using Test-Driven Development from Extreme Programming helps to build a minimal working solution. First we need to encode the conditions for success in tests.
Step 8
Implement
Then the production classes are put together piece by piece to let the tests succeed. This step includes several iterations to build the software.
Step 9
Functional tests
Finally some words on functional testing and how to do it with Together, JUnitX and XPTest.
Summary Lessons learned and an outlook on future directions you can take to learn more about topics not fully covered in the tutorial.


Additional material

Appendix A
Installation
Instructions on how to install all the required applications and libraries for the tutorial.
Appendix B
Sources
Complete sources of all development steps and iterations.
Appendix C
Non-public code tests
More information on how to test non-public code using JUnitX and XPTest.
Appendix D
Links
Links and recommended reading.

Now start with the first step, the customer's story.

next