Name

TestSuite

Description

TestSuite (see Figure B-10) is a class representing a collection of Tests. Since it implements Test, it can be run just like a TestCase. When run, a TestSuite runs all the Tests it contains. It may contain both TestCases and other TestSuites.

A TestSuite can be constructed by giving it the class name of a TestCase. The TestSuite constructor uses reflection to find all methods in the TestCase having names starting with test. The code below adds all of BookTest’s test methods to a TestSuite and runs it:

TestSuite test = new TestSuite( BookTest.class );
test.run( new TestResult( ) );

Tests also can be added to a TestSuite using the addTest( ) method.

The class TestSuite
Figure B-10. The class TestSuite

Declaration

public class TestSuite

extends Object

implements Test

Constructors

TestSuite( )

A constructor that creates an empty TestSuite.

TestSuite(String name)

A constructor that creates an empty TestSuite with the given name.

TestSuite(Class class)

A constructor that takes a Class, uses reflection to find all methods with names starting with test, and adds them to the TestSuite as test methods.

TestSuite(Class class, String name)

A constructor that creates a TestSuite with the given name and all test methods found in the Class, as described for the previous constructor.

Public Methods

void addTest(Test test)

Adds a Test to the TestSuite.

void addTestSuite(Class testClass)

Adds the test ...

Get Unit Test Frameworks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.