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 ObjectConstructors
-
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
TestListenerto receive events from thisTestResult.-
void endTest(Test test) Informs the listeners that
Testcompleted.-
int errorCount( ) Gets the number of errors in the results.
-
Enumeration errors( ) Gets an
Enumerationof the errors.-
int failureCount( ) Gets the number of failures in the results.
-
Enumeration failures( ) Gets an
Enumerationof the failures.-
void removeListener(TestListener listener)
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
