Most visited

Recently visited

Added in API level 1

TestSuite

public class TestSuite
extends Object implements Test

java.lang.Object
   ↳ junit.framework.TestSuite
Known Direct Subclasses


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:

Summary

Public constructors

TestSuite()

Constructs an empty TestSuite.

TestSuite(Class<?> theClass)

Constructs a TestSuite from the given class.

TestSuite(Class<? extends TestCase> theClass, String name)

Constructs a TestSuite from the given class with the given name.

TestSuite(String name)

Constructs an empty TestSuite.

TestSuite(Class...<?> classes)

Constructs a TestSuite from the given array of classes.

TestSuite(Class[]<? extends TestCase> classes, String name)

Constructs a TestSuite from the given array of classes with the given name.

Public methods

void addTest(Test test)

Adds a test to the suite.

void addTestSuite(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(Class<?> theClass, String name)

...as the moon sets over the early morning Merlin, Oregon mountains, our intrepid adventurers type...

String 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.

void run(TestResult result)

Runs the tests and collects their result in a TestResult.

void runTest(Test test, TestResult result)
void setName(String name)

Sets the name of the suite.

Test testAt(int index)

Returns the test at the given index

int testCount()

Returns the number of tests in this suite

Enumeration<Test> tests()

Returns the tests as an enumeration

String toString()

Returns a string representation of the object.

static Test warning(String message)

Returns a test which will fail and log a warning message.

Inherited methods

From class java.lang.Object
From interface junit.framework.Test

Public constructors

TestSuite

Added in API level 1
TestSuite ()

Constructs an empty TestSuite.

TestSuite

Added in API level 16
TestSuite (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 were written at 2337 meters in the Hueffihuette, Kanton Uri

Parameters
theClass Class

TestSuite

Added in API level 16
TestSuite (Class<? extends TestCase> theClass, 
                String name)

Constructs a TestSuite from the given class with the given name.

Parameters
theClass Class
name String

See also:

TestSuite

Added in API level 1
TestSuite (String name)

Constructs an empty TestSuite.

Parameters
name String

TestSuite

Added in API level 16
TestSuite (Class...<?> classes)

Constructs a TestSuite from the given array of classes.

Parameters
classes Class: TestCases

TestSuite

Added in API level 16
TestSuite (Class[]<? extends TestCase> classes, 
                String name)

Constructs a TestSuite from the given array of classes with the given name.

Parameters
classes Class
name String

See also:

Public methods

addTest

Added in API level 1
void addTest (Test test)

Adds a test to the suite.

Parameters
test Test

addTestSuite

Added in API level 16
void addTestSuite (Class<? extends TestCase> testClass)

Adds the tests from the given class to the suite

Parameters
testClass Class

countTestCases

Added in API level 1
int countTestCases ()

Counts the number of test cases that will be run by this test.

Returns
int

createTest

Added in API level 16
Test createTest (Class<?> theClass, 
                String name)

...as the moon sets over the early morning Merlin, Oregon mountains, our intrepid adventurers type...

Parameters
theClass Class
name String
Returns
Test

getName

Added in API level 1
String getName ()

Returns the name of the suite. Not all test suites have a name and this method can return null.

Returns
String

getTestConstructor

Added in API level 16
Constructor<?> getTestConstructor (Class<?> theClass)

Gets a constructor which takes a single String as its argument or a no arg constructor.

Parameters
theClass Class
Returns
Constructor<?>
Throws
NoSuchMethodException

run

Added in API level 1
void run (TestResult result)

Runs the tests and collects their result in a TestResult.

Parameters
result TestResult

runTest

Added in API level 1
void runTest (Test test, 
                TestResult result)

Parameters
test Test
result TestResult

setName

Added in API level 1
void setName (String name)

Sets the name of the suite.

Parameters
name String: the name to set

testAt

Added in API level 1
Test testAt (int index)

Returns the test at the given index

Parameters
index int
Returns
Test

testCount

Added in API level 1
int testCount ()

Returns the number of tests in this suite

Returns
int

tests

Added in API level 1
Enumeration<Test> tests ()

Returns the tests as an enumeration

Returns
Enumeration<Test>

toString

Added in API level 1
String toString ()

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Returns
String a string representation of the object.

warning

Added in API level 16
Test warning (String message)

Returns a test which will fail and log a warning message.

Parameters
message String
Returns
Test

Hooray!