GNU Info

Info Node: (python2.1-lib.info)TestResult Objects

(python2.1-lib.info)TestResult Objects


Next: TestLoader Objects Prev: TestSuite Objects Up: unittest
Enter node , (file) or (file)node

TestResult Objects
------------------

A `TestResult' object stores the results of a set of tests.  The
`TestCase' and `TestSuite' classes ensure that results are properly
stored; test authors do not need to worry about recording the outcome
of tests.

Testing frameworks built on top of `unittest' may want access to the
`TestResult' object generated by running a set of tests for reporting
purposes; a `TestResult' instance is returned by the `TestRunner.run()'
method for this purpose.

Each instance holds the total number of tests run, and collections of
failures and errors that occurred among those test runs.  The
collections contain tuples of `(TESTCASE, EXCEPTIONINFO)', where
EXCEPTIONINFO is a tuple as returned by `sys.exc_info()'.

`TestResult' instances have the following attributes that will be of
interest when inspecting the results of running a set of tests:

`errors'
     A list containing pairs of `TestCase' instances and the
     `sys.exc_info()' results for tests which raised an exception but
     did not signal a test failure.

`failures'
     A list containing pairs of `TestCase' instances and the
     `sys.exc_info()' results for tests which signalled a failure in
     the code under test.

`testsRun'
     The number of tests which have been started.

`wasSuccessful()'
     Returns true if all tests run so far have passed, otherwise returns
     false.

The following methods of the `TestResult' class are used to maintain
the internal data structures, and mmay be extended in subclasses to
support additional reporting requirements.  This is particularly useful
in building GUI tools which support interactive reporting while tests
are being run.

`startTest(test)'
     Called when the test case TEST is about to be run.

`stopTest(test)'
     Called when the test case TEST has been executed, regardless of
     the outcome.

`addError(test, err)'
     Called when the test case TEST raises an exception without
     signalling a test failure.  ERR is a tuple of the form returned by
     `sys.exc_info()':  `(TYPE, VALUE, TRACEBACK)'.

`addFailure(test, err)'
     Called when the test case TEST signals a failure.  ERR is a tuple
     of the form returned by `sys.exc_info()':  `(TYPE, VALUE,
     TRACEBACK)'.

`addSuccess(test)'
     This method is called for a test that does not fail; TEST is the
     test case object.

One additional method is available for `TestResult' objects:

`stop()'
     This method can be called to signal that the set of tests being run
     should be aborted.  Once this has been called, the `TestRunner'
     object return to its caller without running any additional tests.
     This is used by the `TextTestRunner' class to stop the test
     framework when the user signals an interrupt from the keyboard.
     GUI tools which provide runners can use this in a similar manner.


automatically generated by info2www version 1.2.2.9