Name
TestResult
Description
TestResult
(see Figure B-9) is a class used to collect unit test results.
The information collected includes a count of tests run and any
failures or errors produced. Failures and errors are represented as
instances of TestFailure
. A
TestResult
runs a Test
by
calling its runBare( )
method.
A set of unit tests is run by creating an empty
TestResult
and calling
run(TestResult)
on each Test
,
passing the TestResult
as a collecting parameter.
At the end, the set of results is retrieved from the
TestResult
and reported.
A TestResult
also is created when the method
Test.run( )
is used to execute a
Test
.
Declaration
public class TestResult extends Object
Constructors
-
TestResult( )
A constructor creating an empty
TestResult
.
Public Methods
-
void addError(Test test, Throwable t)
Adds an error to the results.
-
void addFailure(Test test, AssertionFailedError e)
Adds a failure to the results.
-
void addListener(TestListener listener)
Registers a
TestListener
to receive events from thisTestResult
.-
void endTest(Test test)
Informs the listeners that
Test
completed.-
int errorCount( )
Gets the number of errors in the results.
-
Enumeration errors( )
Gets an
Enumeration
of the errors.-
int failureCount( )
Gets the number of failures in the results.
-
Enumeration failures( )
Gets an
Enumeration
of the failures.-
void removeListener(TestListener listener)
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.