consciouscode.junit
Class AutoSuite

java.lang.Object
  extended by junit.framework.TestSuite
      extended by consciouscode.junit.TestSuite
          extended by consciouscode.junit.AutoSuite
All Implemented Interfaces:
junit.framework.Test

public class AutoSuite
extends TestSuite

A JUnit test suite that automatically builds its tests from a class path.

An AutoSuite has the following configuration properties:

Given these values, AutoSuite gathers a set of tests by traversing the test path in search of .class files whose contained class: Each class that meets these requirements is added to the test suite.

There is a special pseudo-suite named "all" that represents all discovered test classes, no matter what AUTO_SUITES are given (although the field itself must be defined and not null). Use "all" when you want to run the complete set of tests.

The AUTO_SUITES value should be a whitespace- or comma-separated list of suite names. Some values have special behavior:

A recommended convention is to have a test suite called "common" that is intended to be run with great regularity (ideally with every compile) and that should therefore run within at most a couple minutes. This can be achieved incrementally by creating each test class with the following line:

    public static final String AUTO_SUITES = "common";
When the common suite takes too long to run, selected classes can be pruned from the suite by editing their AUTO_SUITES declarations, replacing "common" with different specialized suite names.

It can be particularly useful to define your AUTO_SUITES in base classes shared by many test cases. Using this technique, a few such declarations will cover your entire test hierarchy, while staying easy to maintain.

Acknowledgments

This class is based on ideas from the JavaWorld article JUnit Best Practices by Andy Schneider.


Field Summary
static String ALL_SUITES_TAG
           
static String REQUIRED_SUITE_TAG
           
static String STATIC_SUITE_FIELD_NAME
           
static String SUITE_PROPERTY
           
static String TEST_PATH_PROPERTY
           
 
Constructor Summary
AutoSuite(String testPath)
           
AutoSuite(String testPath, String desiredSuite)
           
 
Method Summary
static junit.framework.Test suite()
          Construct an AutoSuite parameterized by the following system properties: consciouscode.junit.AutoSuite.testPath consciouscode.junit.AutoSuite.suite See the class documentation for details on these values.
 
Methods inherited from class consciouscode.junit.TestSuite
addTestSuite, classExtendsTestSuite
 
Methods inherited from class junit.framework.TestSuite
addTest, countTestCases, createTest, getName, getTestConstructor, run, runTest, setName, testAt, testCount, tests, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TEST_PATH_PROPERTY

public static final String TEST_PATH_PROPERTY
See Also:
Constant Field Values

SUITE_PROPERTY

public static final String SUITE_PROPERTY
See Also:
Constant Field Values

STATIC_SUITE_FIELD_NAME

public static final String STATIC_SUITE_FIELD_NAME
See Also:
Constant Field Values

ALL_SUITES_TAG

public static final String ALL_SUITES_TAG
See Also:
Constant Field Values

REQUIRED_SUITE_TAG

public static final String REQUIRED_SUITE_TAG
See Also:
Constant Field Values
Constructor Detail

AutoSuite

public AutoSuite(String testPath)
          throws IOException
Throws:
IOException

AutoSuite

public AutoSuite(String testPath,
                 String desiredSuite)
          throws IOException
Throws:
IOException
Method Detail

suite

public static junit.framework.Test suite()
                                  throws IOException
Construct an AutoSuite parameterized by the following system properties: See the class documentation for details on these values.

Throws:
IOException


Copyright © 2001–2012 Todd V. Jonker. All Rights Reserved.