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.
![]() |
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
TestSuitewith the given name.-
TestSuite(Class class) A constructor that takes a
Class, uses reflection to find all methods with names starting withtest, and adds them to theTestSuiteas test methods.-
TestSuite(Class class, String name) A constructor that creates a
TestSuitewith the given name and all test methods found in theClass, as described for the previous constructor.
Public Methods
-
void addTest(Test test) Adds a
Testto theTestSuite.-
void addTestSuite(Class testClass) Adds the test ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access
