Package junit.framework
Class TestSuite
java.lang.Object
junit.framework.TestSuite
- All Implemented Interfaces:
Test
- Direct Known Subclasses:
ActiveTestSuite
A
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);
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty TestSuite.Constructs a TestSuite from the given class.Constructs a TestSuite from the given array of classes.Constructs a TestSuite from the given array of classes with the given name.Constructs a TestSuite from the given class with the given name.Constructs an empty TestSuite. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a test to the suite.private void
addTestMethod
(Method m, List<String> names, Class<?> theClass) private void
addTestsFromTestCase
(Class<?> theClass) void
addTestSuite
(Class<? extends TestCase> testClass) Adds the tests from the given class to the suite.int
Counts the number of test cases that will be run by this test.static Test
createTest
(Class<?> theClass, String name) ...as the moon sets over the early morning Merlin, Oregon mountains, our intrepid adventurers type...getName()
Returns the name of the suite.static Constructor
<?> getTestConstructor
(Class<?> theClass) Gets a constructor which takes a single String as its argument or a no arg constructor.private boolean
private boolean
void
run
(TestResult result) Runs the tests and collects their result in a TestResult.void
runTest
(Test test, TestResult result) void
Sets the name of the suite.testAt
(int index) Returns the test at the given index.private Test
testCaseForClass
(Class<?> each) int
Returns the number of tests in this suite.tests()
Returns the tests as an enumeration.toString()
static Test
Returns a test which will fail and log a warning message.
-
Field Details
-
fName
-
fTests
-
-
Constructor Details
-
TestSuite
public TestSuite()Constructs an empty TestSuite. -
TestSuite
Constructs a TestSuite from the given class. Adds all the methods starting with "test" as test cases to the suite. Parts of this method were written at 2337 meters in the Hueffihuette, Kanton Uri -
TestSuite
Constructs a TestSuite from the given class with the given name.- See Also:
-
TestSuite
Constructs an empty TestSuite. -
TestSuite
Constructs a TestSuite from the given array of classes.- Parameters:
classes
-TestCase
s
-
TestSuite
Constructs a TestSuite from the given array of classes with the given name.- See Also:
-
-
Method Details
-
createTest
...as the moon sets over the early morning Merlin, Oregon mountains, our intrepid adventurers type... -
getTestConstructor
Gets a constructor which takes a single String as its argument or a no arg constructor.- Throws:
NoSuchMethodException
-
warning
Returns a test which will fail and log a warning message. -
addTestsFromTestCase
-
testCaseForClass
-
addTest
Adds a test to the suite. -
addTestSuite
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:
countTestCases
in interfaceTest
-
getName
Returns the name of the suite. Not all test suites have a name and this method can return null. -
run
Runs the tests and collects their result in a TestResult. -
runTest
-
setName
Sets the name of the suite.- Parameters:
name
- the name to set
-
testAt
Returns the test at the given index. -
testCount
public int testCount()Returns the number of tests in this suite. -
tests
Returns the tests as an enumeration. -
toString
-
addTestMethod
-
isPublicTestMethod
-
isTestMethod
-