Logo
 
 
 
spacer

Test Organization

The following pages should describe some test organization issues. The description concentrates on developer testing.

Directory Layout

Test case written as JUnit test case should reside in the src directory test. The package name of each JUnit test case file should reflect the subsystem package name plus package name test, eg. testing foo.bar.A.java should have name ATestCase.java, residing in directroy ${test.dir}/foo/bar/test.

The following table should help to understand the mapping for the JUnit files:

Testee Name  JUnit Name 
Package foo.bar  Package foo.bar.test 
Filename A.java  Filename ATestCase 
Fullpath name ${java.dir}/foo/bar/A.java  Fullpath name ${test.dir}/foo/bar/test/ATestCase.java 

The java source code of ATestCase.java may look like this:

package foo.bar.test;
import junit.framework.*;
public class ATestCase {
  public ATestCase( String name ) {
    super(name);
  }
  void test1() throws Exception {
    // do testing here
  }
}

Compiling tests

In some J2EE enviroment the JUnit test cases act like a client application. For example JUnit test cases acting as EJB clients, or simple web clients.

In that cases your JUnit test cases may require some different jars than the testee classes. This should be taken into account by defining addition Ant classpath ids.

Launching tests

Having written JUnit tests, you need to launch them.

An easy way is to write an Ant target test launching the test for each *TestCase file. Moreover optionally you may want to launch the test reporting task immediatly

A simple Ant snippet for testing, and test reports

<target name="test" depends="compile-test" 
  description="--&gt; junit test">
  
  <!-- by default run all testcases
  -->
  <property name="test-package" value="**" />
  <property name="test.include" value="**/test/*TestCase.class" />
  <property name="test.exclude" value="**/AllTests.class" />
  
  <echo>
    Testing test-package ${test-package}
    Testing test.include ${test.include}
    Testing test.exclude ${test.exclude}
  </echo>
  
  <property name="test-type" value="xml" />
  
  <junit fork="yes" 
    printsummary="yes" 
    haltonfailure="no"
    haltonerror="no">
    
    <classpath refid="client.classpath" />
  
    <formatter type="${test-type}" />
  
    <batchtest todir="${test.report.dir}">
      <fileset dir="${class.dir}">
        <include name="${test.include}" />
        <exclude name="${test.exclude}" />
      </fileset>
    </batchtest>
  </junit>
</target>

<target name="generate-test-report" depends="test"
  description="--&gt; Generate test report">
  <junitreport todir="${test.report.dir}">
    <fileset dir="${test.report.dir}">
      <include name="TEST-*.xml"/>
    </fileset>
    <report format="frames" todir="${test.report.dir}/html"/>
  </junitreport>
</target>
spacer

Events
Party 1
Party 2

spacer
 
 
(C) 2001 Huber Bernhard