This topic explains how to access and explore C++test’s automatically-generated test cases.

Sections include:

Accessing the Test Cases

The automatically-generated test cases are saved in test suite files. With the default settings, C++test generates one test suite per tested file. It can also be configured to generate one test suite per function (see Test suite tab for details).

To view the generated test cases:

  1. In the project tree, locate the test suite file that C++test generated.
  2. Double-click the project tree node that represents the generated test class. The generated test class file will open in an editor.

Understanding the Test Cases

Test suites contain test cases, using the following architecture:

If more functions are later added to the file under test, then test generation is run on the updated file, additional test cases will be added to the original test suite file.

Context and Include Macros

Every test suite begins with the following two macros:

The files specified by these two macros should always match the name of the file under test. If the name of the file under test changes, the values of these macros must be modified accordingly.

Relative paths can be used in both of these macros. Relative paths must start with "./" or with "../".

Postcondition Macros

The following postcondition macros, are used to report the value that a variable or class member had during the test execution:

The results of these macros (all the asserted values reported) are displayed in the Quality Tasks view. Any test case with reported postconditions can be automatically validated for use in regression testing. Validation changes the *_POST_CONDITION_* macros into assertions that will fail if a subsequent test does not produce the expected (validated) value. This is especially useful for automated generation of a regression base for legacy code. For details on validation, see Verifying Test Cases for Regression Testing.

Other Macros

Assertion macros are added to the test case when postconditions are verified.

Additionally, other macros may be added manually, based on your testing needs.

For a list of macros that can be used in test cases, see C++test API Documentation.

Test Functions

Automatically-generated test cases sometimes include special functions (e.g., for accessing minimum of maximum values).

To generate test cases using different numeric values, the C++test runtime library contains a set of functions that returns min/max values of integral and floating point types. The functions are described in the following table. All listed functions can be used in user-defined test cases.

char cpptestLimitsGetMaxChar(void);Returns maximum value of char type.
char cpptestLimitsGetMinChar(void);Returns minimum value of char type.
signed char cpptestLimitsGetMaxSigned Char(void);Returns minimum value of char type.
signed char cpptestLimitsGetMinSigned Char(void);Returns minimum value of signed char type.
unsigned char cpptestLimitsGetMaxUnsigned Char(void);Returns maximum value of unsigned char type.
short cpptestLimitsGetMaxShort(void);Returns maximum value of short type.
short cpptestLimitsGetMinShort(void);Returns minimum value of short type.
unsigned short cpptestLimitsGetMax UnsignedShort(void);Returns maximum value of unsigned short type.
int cpptestLimitsGetMaxInt(void);Returns maximum value of int type.
int cpptestLimitsGetMinInt(void);Returns minimum value of int type.
unsigned int cpptestLimitsGetMaxUnsigned Int(void);Returns maximum value of unsigned int type.
long cpptestLimitsGetMaxLong(void);Returns maximum value of long type.
long cpptestLimitsGetMinLong(void);Returns minimum value of long type.
unsigned long cpptestLimitsGetMaxUnsigned Long(void);Returns maximum value of unsigned long type.
float cpptestLimitsGetMaxPosFloat(void);Returns maximum positive value of float type.
float cpptestLimitsGetMinNegFloat(void);Returns minimum negative value of float type.
float cpptestLimitsGetMaxNegFloat(void);Returns maximum negative value of float type.
float cpptestLimitsGetMinPosFloat(void);Returns minimum positive value of float type.
double cpptestLimitsGetMaxPosDouble(void);Returns maximum positive value of double type.
double cpptestLimitsGetMinNegDouble(void);Returns minimum negative value of double type.
double cpptestLimitsGetMaxNegDouble(void);Returns maximum negative value of double type.
double cpptestLimitsGetMinPosDouble(void);Returns minimum positive value of double type.
long double cpptestLimitsGetMaxPosLong Double(void);Returns maximum positive value of long double type.
long double cpptestLimitsGetMinNegLong Double(void);Returns minimum negative value of long double type.
long double cpptestLimitsGetMaxNegLong Double(void);Returns maximum negative value of long double type.
long double cpptestLimitsGetMinPosLongDou-ble(void);Returns maximum positive value of long double type.

Understanding Automatically-Generated Stubs

See Understanding and Customizing Automatically-Generated Stubs.