TestResult

   
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 .

Figure B-9. The class TestResult
figs/utf_ab09.gif

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 this TestResult .


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)

Unregisters a TestListener .


int runCount( )

Gets the number of tests run.


void runProtected(Test test, Protectable p)

Runs a Protectable and associates any failures or errors with Test . The Protectable is assumed to run the Test 's test method.


boolean shouldStop( )

Returns the stop flag.


void startTest(Test test)

Informs listeners that Test is starting. Also increments fRunTests by the amount returned by Test.countTestCases( ) .


void stop( )

Sets the stop flag.


boolean wasSuccessful( )

Returns TRUE if there are no failures or errors in the results.

Protected/Private Methods


protected void run(TestCase test)

A method to run a TestCase .


private Vector cloneListeners( )

A method to return a copy of the listeners.

Attributes


protected Vector fErrors

A collection of TestFailures representing errors.


protected Vector fFailures

A collection of TestFailures representing failures.


protected Vector fListeners

A list of TestListeners for this TestResult .


protected int fRunTests

A counter to record the number of tests run.


private boolean fStop

A stop flag indicating that tests should stop running.



Unit Test Frameworks
Unit Test Frameworks
ISBN: 0596006896
EAN: 2147483647
Year: 2006
Pages: 146
Authors: Paul Hamill

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net