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.

The class TestCase, base class for all test objects
Figure C-18. The class TestCase, base class for all test objects

Declaration

class TestCase : public Test, public TestFixture

Constructors/Destructors

TestCase(string name)

Constructs a TestCase with the given name.

TestCase( )

The default constructor used by TestCaller to create a temporary TestCase. Should not be used directly, since it creates a TestCase with no name.

~TestCase( )

A destructor.

Public Methods

virtual int countTestCases( ) const

Returns 1, the number of test cases contained in a base TestCase. Descendants of TestCase may contain multiple test cases.

string getName( ) const

Returns the TestCase name.

virtual TestResult *run( )

A convenience method that runs this TestCase and returns a new ...

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.