public class TestSuite extends java.lang.Object implements Test
TestSuite
is a Composite
of Tests.
It runs a collection of test cases. Here is an example using
the dynamic test definition.
TestSuite suite= new TestSuite(); suite.addTest(new MathTest("testAdd")); suite.addTest(new MathTest("testDivideByZero"));
Alternatively, a TestSuite can extract the tests to be run automatically. To do so you pass the class of your TestCase class to the TestSuite constructor.
TestSuite suite= new TestSuite(MathTest.class);
This constructor creates a suite with all the methods starting with "test" that take no arguments.
A final option is to do the same for a large array of test classes.
Class[] testClasses = { MathTest.class, AnotherTest.class }; TestSuite suite= new TestSuite(testClasses);
Test
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
fName |
private java.util.Vector<Test> |
fTests |
Constructor and Description |
---|
TestSuite()
Constructs an empty TestSuite.
|
TestSuite(java.lang.Class<?>... classes)
Constructs a TestSuite from the given array of classes.
|
TestSuite(java.lang.Class<?> theClass)
Constructs a TestSuite from the given class.
|
TestSuite(java.lang.Class<? extends TestCase>[] classes,
java.lang.String name)
Constructs a TestSuite from the given array of classes with the given name.
|
TestSuite(java.lang.Class<? extends TestCase> theClass,
java.lang.String name)
Constructs a TestSuite from the given class with the given name.
|
TestSuite(java.lang.String name)
Constructs an empty TestSuite.
|
Modifier and Type | Method and Description |
---|---|
void |
addTest(Test test)
Adds a test to the suite.
|
private void |
addTestMethod(java.lang.reflect.Method m,
java.util.List<java.lang.String> names,
java.lang.Class<?> theClass) |
private void |
addTestsFromTestCase(java.lang.Class<?> theClass) |
void |
addTestSuite(java.lang.Class<? extends TestCase> testClass)
Adds the tests from the given class to the suite.
|
int |
countTestCases()
Counts the number of test cases that will be run by this test.
|
static Test |
createTest(java.lang.Class<?> theClass,
java.lang.String name)
...as the moon sets over the early morning Merlin, Oregon
mountains, our intrepid adventurers type...
|
java.lang.String |
getName()
Returns the name of the suite.
|
static java.lang.reflect.Constructor<?> |
getTestConstructor(java.lang.Class<?> theClass)
Gets a constructor which takes a single String as
its argument or a no arg constructor.
|
private boolean |
isPublicTestMethod(java.lang.reflect.Method m) |
private boolean |
isTestMethod(java.lang.reflect.Method m) |
void |
run(TestResult result)
Runs the tests and collects their result in a TestResult.
|
void |
runTest(Test test,
TestResult result) |
void |
setName(java.lang.String name)
Sets the name of the suite.
|
Test |
testAt(int index)
Returns the test at the given index.
|
private Test |
testCaseForClass(java.lang.Class<?> each) |
int |
testCount()
Returns the number of tests in this suite.
|
java.util.Enumeration<Test> |
tests()
Returns the tests as an enumeration.
|
java.lang.String |
toString() |
static Test |
warning(java.lang.String message)
Returns a test which will fail and log a warning message.
|
private java.lang.String fName
private java.util.Vector<Test> fTests
public TestSuite()
public TestSuite(java.lang.Class<?> theClass)
public TestSuite(java.lang.Class<? extends TestCase> theClass, java.lang.String name)
TestSuite(Class)
public TestSuite(java.lang.String name)
public TestSuite(java.lang.Class<?>... classes)
classes
- TestCase
spublic TestSuite(java.lang.Class<? extends TestCase>[] classes, java.lang.String name)
TestSuite(Class[])
public static Test createTest(java.lang.Class<?> theClass, java.lang.String name)
public static java.lang.reflect.Constructor<?> getTestConstructor(java.lang.Class<?> theClass) throws java.lang.NoSuchMethodException
java.lang.NoSuchMethodException
public static Test warning(java.lang.String message)
private void addTestsFromTestCase(java.lang.Class<?> theClass)
private Test testCaseForClass(java.lang.Class<?> each)
public void addTest(Test test)
public void addTestSuite(java.lang.Class<? extends TestCase> testClass)
public int countTestCases()
countTestCases
in interface Test
public java.lang.String getName()
public void run(TestResult result)
public void runTest(Test test, TestResult result)
public void setName(java.lang.String name)
name
- the name to setpublic Test testAt(int index)
public int testCount()
public java.util.Enumeration<Test> tests()
public java.lang.String toString()
toString
in class java.lang.Object
private void addTestMethod(java.lang.reflect.Method m, java.util.List<java.lang.String> names, java.lang.Class<?> theClass)
private boolean isPublicTestMethod(java.lang.reflect.Method m)
private boolean isTestMethod(java.lang.reflect.Method m)