To edit or add content to this Wiki, you can simply create a new account at

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

JUnit tests of the Project WOnder frameworks are included in the source. For each package, there is or can be a "Tests" directory next to the "Sources" directory. The test classes can be in the same package as the class being tested. For example, the location of the ERXArrayUtilities class in Project WOnder and the test class are below. For information on checking out the sources for Project WOnder, go to the at sourceforge project svn page. See the JUnit home page for more information on JUnit.


Note that this document is not describing any issues related to integrating these tests into an eclipse environment.

Building and Running Existing Tests

cd ~/<latestGreatest>/Wonder
ant tests.all
( cd Frameworks/Core/ERExtensions ; ant all -Dinclude.tests=true )

The first ant command will do the same as "ant all" and will also build and install classes in the "Tests" directories. The names of test classes need to end in "Test". The second ant command will run all the JUnit tests found in the frameworks. The last command will run "ant all" on just the ERExtensions framework (after cd-ing into the proper directory) and will build and install it and its test classes.

Adding Tests to an Existing Class

Any method in a test class that matches the signature requirements will be run as a test. The method must be public, must return void and the name of the method must begin with "test." The method itself can do anything it wants. It can be suggested, though, that it can call methods such as "Assert.assertTrue" in the junit framework. See the JUnit javadoc for more details.

Adding a Test Class to a Package Already Having Tests

Every framework should have a class which subclasses the junit.framework.TestSuite class and which will load the test classes for that framework. For example:

% cat Frameworks/Core/ERExtensions/Tests/er/extensions/

package er.extensions;

import junit.framework.Test;
import junit.framework.TestSuite;

/** Tests of the public API of the ERXExtensions framework.
 * @author, Ray Kiddy
public class ERExtensionsTest extends TestSuite {

    public static Test suite() {
        TestSuite suite = new TestSuite("Tests for ERExtensions");
        // ....
        return suite;

There may be better ways to have this class load the test classes, but this is what is being done now. If a TestSuite subclass does not exist for a framework, see the next section.

Adding Testability to a Package

There are a few things that need to be done so that a framework can include tests.

1) The "Tests" directory must be created at the top level of the project, next to the "Sources" directory. When test classes are found under that directory, the Project WOnder ant build system will automatically build those sources when the appropriate ant command is used.

Note that tests are assumed to be for framework projects only. One can obviously have junit tests in examples and applications, but they will not be run by the ant commands described above. (TODO: Can we point to other pages that have current information about WOUnitTest, Selenium tests and other harnesses?)

2) Every framework has a target for it in the "Build/build/build.xml" file in the Project WOnder sources. For example, one can see the following in this file:

     <target name="ERChronic.all">
        <antcall target="global.framework.${build.action}" >
            <param name="project.principal.class" value="" />
            <param name="" value="ERChronic" />
            <param name="project.dir" value="Frameworks/Misc/ERChronic" />
            <param name="wo.external.root.bundles" value="${frameworks.wonder.core}" />
            <param name="test.className" value="er.chronic.ChronicTestSuite" />

The existence of the "test.className" parameter will cause the tests in this framework to be invoked by the appropriate ant command. As you may guess, the value of this parameter must be the fully-qualified class name of the TestSuite subclass for this framework.

Note that, at this time, the test classes must have the same build dependencies as the framework being tested. If the tests require different dependencies, it is not yet clear how that can best be handled. So, if you need to add a dependency for your tests, add that to the "<framework>.all" target. Hopefully it will not interfere with the building of the framework itself. (TODO: Add a parameter for "wo.external.test.bundles", same as "wo.external.root.bundles?) Also, if the antcall target above is "global.application.${build.action}", this will not work. As said above, building and running these tests works only for frameworks at this time.

See the "global.compile" target in the Build/build/generic.xml for the <wocompile> changes that cause test sources to be built.

3) Information for the framework must be added to the "" target in the Build/build/build.xml file. For example:

    <target name="">
        <antcall target="ERExtensions.all"><param name="build.action" value="test" /></antcall>
        <antcall target="ERChronic.all"><param name="build.action" value="test" /></antcall>

4) For now, the runtime dependencies of any tests must be included in the <classpath> in the "global.framework.test" target in the Build/build/generic.xml file. The classpath includes jar files in ${build.root}, ${wo.local.frameworks}, ${wo.system.frameworks}, so this should work for most frameworks.

(TODO: Frameworks declare their build dependencies in the "<framework>.all" target. Can they also declare their test run dependencies? Where would be the best place to do this?)

If there are questions about this testing, please send mail to the Project WOnder mailing list and/or to

  • No labels