Package junit.framework
Class TestSuite
- java.lang.Object
-
- junit.framework.TestSuite
-
- All Implemented Interfaces:
Test
- Direct Known Subclasses:
ActiveTestSuite
public class TestSuite extends java.lang.Object implements Test
ATestSuiteis aCompositeof 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);- See Also:
Test
-
-
Constructor Summary
Constructors Constructor Description TestSuite()Constructs an empty TestSuite.TestSuite(java.lang.Class theClass)Constructs a TestSuite from the given class.TestSuite(java.lang.Class[] classes)Constructs a TestSuite from the given array of classes.TestSuite(java.lang.Class[] classes, java.lang.String name)Constructs a TestSuite from the given array of classes with the given name.TestSuite(java.lang.Class 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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddTest(Test test)Adds a test to the suite.voidaddTestSuite(java.lang.Class testClass)Adds the tests from the given class to the suiteintcountTestCases()Counts the number of test cases that will be run by this test.static TestcreateTest(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.StringgetName()Returns the name of the suite.static java.lang.reflect.ConstructorgetTestConstructor(java.lang.Class theClass)Gets a constructor which takes a single String as its argument or a no arg constructor.voidrun(TestResult result)Runs the tests and collects their result in a TestResult.voidrunTest(Test test, TestResult result)voidsetName(java.lang.String name)Sets the name of the suite.TesttestAt(int index)Returns the test at the given indexinttestCount()Returns the number of tests in this suitejava.util.Enumerationtests()Returns the tests as an enumerationjava.lang.StringtoString()static Testwarning(java.lang.String message)Returns a test which will fail and log a warning message.
-
-
-
Constructor Detail
-
TestSuite
public TestSuite()
Constructs an empty TestSuite.
-
TestSuite
public TestSuite(java.lang.Class theClass)
Constructs a TestSuite from the given class. Adds all the methods starting with "test" as test cases to the suite. Parts of this method was written at 2337 meters in the Hueffihuette, Kanton Uri
-
TestSuite
public TestSuite(java.lang.Class theClass, java.lang.String name)Constructs a TestSuite from the given class with the given name.- See Also:
TestSuite(Class)
-
TestSuite
public TestSuite(java.lang.String name)
Constructs an empty TestSuite.
-
TestSuite
public TestSuite(java.lang.Class[] classes)
Constructs a TestSuite from the given array of classes.- Parameters:
classes-
-
TestSuite
public TestSuite(java.lang.Class[] classes, java.lang.String name)Constructs a TestSuite from the given array of classes with the given name.- See Also:
TestSuite(Class[])
-
-
Method Detail
-
createTest
public 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...
-
getTestConstructor
public static java.lang.reflect.Constructor getTestConstructor(java.lang.Class theClass) throws java.lang.NoSuchMethodExceptionGets a constructor which takes a single String as its argument or a no arg constructor.- Throws:
java.lang.NoSuchMethodException
-
warning
public static Test warning(java.lang.String message)
Returns a test which will fail and log a warning message.
-
addTest
public void addTest(Test test)
Adds a test to the suite.
-
addTestSuite
public void addTestSuite(java.lang.Class testClass)
Adds the tests from the given class to the suite
-
countTestCases
public int countTestCases()
Counts the number of test cases that will be run by this test.- Specified by:
countTestCasesin interfaceTest
-
getName
public java.lang.String getName()
Returns the name of the suite. Not all test suites have a name and this method can return null.
-
run
public void run(TestResult result)
Runs the tests and collects their result in a TestResult.
-
runTest
public void runTest(Test test, TestResult result)
-
setName
public void setName(java.lang.String name)
Sets the name of the suite.- Parameters:
name- The name to set
-
testAt
public Test testAt(int index)
Returns the test at the given index
-
testCount
public int testCount()
Returns the number of tests in this suite
-
tests
public java.util.Enumeration tests()
Returns the tests as an enumeration
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-