Step 7a: Unit tests previous   contents   next
next 

Extreme Programming allows a team of experienced programmers to develop software fast. One reason for projects not beeing finished on time because of programmers, is planning and implementing more features than required because they may be useful later. Another is creeping featuritis, that means adding more and more features instead of implementing the most important features first. Test-Driven Development helps a lot with these problems and software instability in general.

In XP everything is tested which can possibly break. Another aspect is that the tests define the required functionality. That means implementation is finished when all tests run successfully. These tests are called unit tests and they are usually implemented by the developer who also writes the respective production classes. During software maintenance, the tests can be run after each change to ensure that nothing else has been broken by the modifications.

Using a framework makes testing a lot easier. JUnit by Kent Beck and Erich Gamma is a framework for testing Java applications. My modifications are available as the standalone-module JUnitX. With JUnit(X) each test is realized as a method. Those methods are collected in test classes derived from the class junitx.framework.TestCase. In order to execute the tests and to see if they succeed or why they fail, they are collected in so-called test suites. The suites implement junitx.framework.TestPackage and can be run by the textual and graphical UIs of JUnit(X).

Before implementing tests you should decide on a strategy where to place the tests. I recommend placing them in a parallel hierarchy using the class naming convention Test<TestedClassName>. Thus the class de.extremejava.url.URL would be tested by a class like unittests.de.extremejava.url.TestURL.

XPTest saves a lot of work in implementing tests by generating code automatically. If you want to use JUnitX without XPTest, you have to write the code yourself. See the various snapshots of the tutorial project to avoid entering all code.

Now we need to configure XPTest in order to create tests.

  previous   contents   next
next 

© 2001 A. Heilwagen