Step 9: Functional tests previous   contents   next
next 

After having implemented the parser driven by tests, the application developer has done his job. Now a tester has to implement functional tests to ensure that the functional requirements have been met. In our case the example URLs in the RFC that can be used for the functional tests. So I just switch hats and we go on testing:

  1. ftp://ftp.is.co.za/rfc/rfc1808.txt
  2. gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles
  3. http://www.math.uio.no/faq/compression-faq/part1.html
  4. mailto:mduerst@ifi.unizh.ch
  5. news:comp.infosystems.www.servers.unix
  6. telnet://melvyl.ucop.edu/

In order to play with URLs, we will implement a small commandline application which helps to run preliminary tests:

package de.extremejava;

import de.extremejava.url.*;

public class URLParser
{
  static public void main (String[] anOptArray)
  throws InvalidURLException
  {
    URL url = URL.valueOf (anOptArray[0]);

    System.out.println ("Parsing: \"" + anOptArray[0] + "\"\n");
    System.out.println ("\n\nbuilt URL again as \""
                          + url.toString () + "\"");
  }
}

Now reconfigure XPTest with its configuration dialog to place the functional test cases in a parallel hierarchy in the package functionaltests. Please change the configuration to use the JUnit text UI.
Define the test methods for the above URLs like this in the class functionaltests.de.extremejava.TestURLParser or copy them from the project snapshots:

  public void testRFCURL ()
  throws InvalidURLException
  {
    URL url = URL.valueOf ("ftp://ftp.is.co.za/rfc/rfc1808.txt");

    assert (url.equals (new URL ("ftp", null, null, "ftp.is.co.za", -1,
                                 "/rfc/rfc1808.txt", null, null)));
  }

For convenience, create a TestPackage class in the package functionaltests containing support for the JUnit test UI. And now that the functional tests are written, we need to update Ant's build.xml file and add the following target:

  <target name = "functionaltests">

    <java  fork        = "yes"
           classname   = "junit.textui.TestRunner"
           taskname    = "JUnitX"
           failonerror = "true">
      <arg value       = "functionaltests.TestPackage" />
      <classpath>
        <pathelement location = "${prj.dir}/classes" />
        <pathelement location = "${junit.jar}"       />
        <pathelement location = "${junitx.jar}"      />
      </classpath>
   </java>

  </target>

Compile everything an run the functional tests with a command in a MS-DOS box or shell like this:

/home/aheilwag/java/XPTools/tools/ant/bin/ant functionaltests

Since we have chosen junit.textui.TestRunner as UI, the output will look like

Buildfile: D:\shared\extreme-java\xptest-tutorial\Build.xml

functionaltests:
   [JUnitX] ......
   [JUnitX] Time: 0
   [JUnitX] 
   [JUnitX] OK (6 tests)
   [JUnitX]
BUILD SUCCESSFUL

Total time: 2 seconds

Our functional tests succeeded. If you want to distribute your application without test code, I recommend to place the test cases in a parallel hierarchy. You can then just leave out the test cases. In order to keep the test proxies compilable but without functionality, you can distribute junitx-dummy-5.0.jar or later with your application.

So that's enough of coding now, lets see what we have achieved.

  previous   contents   next
next 

© 2001 A. Heilwagen