Name
TestCase
Description
The class TestCase
(see Figure C-18) represents a test object. Its purpose is to
run test methods and thereby produce test results.
TestCase may be used in a number of ways. The
simplest way to write a test object is to create a subclass of
TestCase that overrides runTest() with a custom test method. To run the test object, call
the run( ) method, which returns a
TestResult.
More commonly, a subclass of TestFixture is
created with multiple test methods. TestRunner
then uses TestCaller to run the test methods,
creating a new instance of TestCase for each one.
TestCase belongs to the namespace
CppUnit. It is declared in
TestCase.h and implemented in
TestCase.cpp.
![]() |
Declaration
class TestCase : public Test, public TestFixture
Constructors/Destructors
-
TestCase(string name) Constructs a
TestCasewith the given name.-
TestCase( ) The default constructor used by
TestCallerto create a temporaryTestCase. Should not be used directly, since it creates aTestCasewith no name.-
~TestCase( ) A destructor.
Public Methods
-
virtual int countTestCases( ) const Returns 1, the number of test cases contained in a base
TestCase. Descendants ofTestCasemay contain multiple test cases.-
string getName( ) const Returns the
TestCasename.-
virtual TestResult *run( ) A convenience method that runs this
TestCaseand returns a new ...
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
