Name
TestSuite
Description
TestSuite
(see Figure B-10) is a class representing a collection of
Test
s. Since it implements
Test
, it can be run just like a
TestCase
. When run, a TestSuite
runs all the Test
s it contains. It may contain
both TestCase
s and other
TestSuite
s.
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
TestSuite
with 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 theTestSuite
as test methods.-
TestSuite(Class class, String name)
A constructor that creates a
TestSuite
with the given name and all test methods found in theClass
, as described for the previous constructor.
Public Methods
-
void addTest(Test test)
Adds a
Test
to theTestSuite
.-
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.