j2meunit.framework
Class TestSuite

java.lang.Object
  |
  +--j2meunit.framework.TestSuite
All Implemented Interfaces:
Test

public class TestSuite
extends java.lang.Object
implements Test

A TestSuite is a collection of Test instances which can be run together. It is created by adding single tests (normally by using a TestMethod) or other suites to it:

 TestSuite suite = new TestSuite();
 suite.addTest(new MathTest("testAdd"));
 suite.addTest(new MathTest("testDivideByZero"));
 suite.addTest(new ValueTest().suite());
 

Version:
$Revision: 1.4 $
Author:
$author$

Constructor Summary
TestSuite()
          Default constructor.
TestSuite(java.lang.Class theClass, java.lang.String[] testNames)
          Creates a new test suite for certain methods of a particular test case class.
TestSuite(java.lang.String sName)
          To create a test suite with a particular name.
TestSuite(Test rTest)
          To create a test suite initialized with a single test.
TestSuite(Test[] rTests)
          To create a test suite initialized with multiple tests.
 
Method Summary
 void addTest(Test test)
          Adds a test to the suite.
 int countTestCases()
          Counts the number of test cases that will be run by this suite.
 int countTestSteps()
          Counts the number of test steps that will be run by this suite.
 void run(TestResult result)
          Runs the tests and collects their result in a TestResult.
 Test testAt(int index)
          Returns the test at the given index.
 int testCount()
          Returns the number of tests in this suite.
 java.util.Enumeration tests()
          Returns the tests as an enumeration.
 java.lang.String toString()
          Create a string description of the suite.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TestSuite

public TestSuite()
Default constructor.


TestSuite

public TestSuite(java.lang.String sName)
To create a test suite with a particular name.

Parameters:
sName - The name of the test suite.

TestSuite

public TestSuite(Test rTest)
To create a test suite initialized with a single test.

Parameters:
rTest - The test to add to the suite

TestSuite

public TestSuite(Test[] rTests)
To create a test suite initialized with multiple tests.

Parameters:
rTests - The tests to add to the suite

TestSuite

public TestSuite(java.lang.Class theClass,
                 java.lang.String[] testNames)
Creates a new test suite for certain methods of a particular test case class. The methods are defined as strings that should contain the method names. These names will be stored in the created TestCase instances as their names. Because J2ME doesn't provide reflection, the TestCase class must implement the runTest() method and invoke the corresponding methods by doing a string compare with the name attribute of the test case instance.

Since version 1.1 the recommended (and easier) method to create test instances and suites is to use the TestMethod interface to wrap the methods of a test case in an anonymous inner class, initialize a TestCase instance for each, and then hand the test(s) over to one of the constructors of TestSuite that accept Test instances.

Parameters:
theClass - The Class instance of a TestCase subclass
testNames - The names of the methods to run
Method Detail

addTest

public void addTest(Test test)
Adds a test to the suite.

Parameters:
test - The test to add

countTestCases

public int countTestCases()
Counts the number of test cases that will be run by this suite.

Specified by:
countTestCases in interface Test
Returns:
The number of test cases to be run by the suite

countTestSteps

public int countTestSteps()
Counts the number of test steps that will be run by this suite.

Specified by:
countTestSteps in interface Test
Returns:
The number of test steps to be run by the suite
See Also:
Test.countTestSteps()

run

public void run(TestResult result)
Runs the tests and collects their result in a TestResult.

Specified by:
run in interface Test
Parameters:
result - The TestResult to collect the results in

testAt

public Test testAt(int index)
Returns the test at the given index.

Parameters:
index - The index position of the test
Returns:
The test at the index position

testCount

public int testCount()
Returns the number of tests in this suite.

Returns:
The test count of the suite

tests

public java.util.Enumeration tests()
Returns the tests as an enumeration.

Returns:
A java.util.Enumeration for all tests

toString

public java.lang.String toString()
Create a string description of the suite.

Overrides:
toString in class java.lang.Object
Returns:
A description of the suite