consciouscode.junit
Class AutoSuite
java.lang.Object
junit.framework.TestSuite
consciouscode.junit.TestSuite
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:
- String testPath: a list of directories. This value must be
like a Java class path, where each directory has a structure matching
the class package hierarchy. Multiple directory roots are indicated
using the platform's
File.pathSeparator
.
- String desiredSuite: the name of the suite to gather. This
property defaults to
"all"
.
Given these values, AutoSuite gathers a set of tests by traversing the
test path in search of .class
files whose contained class:
- implements interface
Test
;
- is not
abstract
;
- defines or inherits the constant
public static final String AUTO_SUITES
; and
- defines an
AUTO_SUITES
value that either contains the
desired suite name or equals the pseudo-name "*"
.
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 value of
"*"
means that the class will be part of
every suite. The test will run all the time.
- A value of
"all"
means that the class will only be part of
the pseudo-suite "all". The empty string has the same effect.
- A value of
null
means that the class will not be part of any
suite and is completely disabled.
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.
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 junit.framework.TestSuite |
addTest, countTestCases, createTest, getName, getTestConstructor, run, runTest, setName, testAt, testCount, tests, toString |
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
AutoSuite
public AutoSuite(String testPath)
throws IOException
- Throws:
IOException
AutoSuite
public AutoSuite(String testPath,
String desiredSuite)
throws IOException
- Throws:
IOException
suite
public static junit.framework.Test suite()
throws IOException
- 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.
- Throws:
IOException
Copyright © 2001–2012
Todd V. Jonker. All Rights Reserved.