ObjectFab GmbH - Logo JunitDoclet - Logo

Step 4 - Generating Tests With JUnitDoclet

Javadoc is parsing the source code of the application classes. From the collected information, JUnitDoclet writes TestCases and TestSuites preferably to a different directory tree (here: junit/).

  • For each package there is a TestSuite.
  • For each public, non-abstract class there is a TestCase.
  • For each public method there is a test method. In case of accessor tests, set and get are tested together.

Not all the tests can be compiled directly after they have been generated for the first time. But most of them will. The compiler will help you with the others by pointing to code where:

  • A class does not have a public constructor.
  • A class does not have a constructor without parameters (default constructor).
  • An accessor for double or float need some epsilon when comparing two values. (see SampleSubClassTest.java)

There is no wizard but you to fix these problems. But don't be sad, it is easy to solve these problems. Did you ever try to outsmart a wizard that did not produce what you wanted? And after all, the fix remains even during re-generation because it is inside a marker pair.

 
demo/
 build.xml
 lib/
 src/
 junit/
  org/
   junitdoclet/
    demo/
     SampleClassTest.java
     DemoSuite.java
     sub/
      SampleSubClassTest.java
      SubSuite.java
 build/