This section defines macros that can be used to register a test suite and its test cases.

MacroDefinition
CPPTEST_TEST_SUITE(TestSuiteName)Begins the test case registration section in the test suite definition.
CPPTEST_TEST_SUITE_END()Ends the test case registration section in the test suite definition.
CPPTEST_TEST(testCaseName)The default test case registration.
CPPTEST_TEST_EXCEPTION(testcasename, ExceptionType)Used to specify that the given test case is expected to throw an exception. ExceptionType should be used to specify the type of  exception. Since this will be used as the exception declaration in the catch clause, you can  specify ... to indicate that the test case is expected to throw any exception.
CPPTEST_TEST_ERROR(testcasename, ErrorCode)

Used to register a test case that is expected to cause a runtime error (e.g., division by zero, access violation, timeout, calling the exit() function etc.) The ErrorCode to be used in the macro can be taken from the C++test runtime problem report. For instance, if a test case "test_0" causes a timeout, C++test  will report the following error: Timeout (5 seconds) reached. Test interrupted.

[CPPTEST_TIMEOUT]. If this is the expected behavior for the particular set of pre-conditions and you want to keep this test case as the regression test, the default test case registration line:

  CPPTEST_TEST(test_0);

should be changed to:

  CPPTEST_TEST_ERROR(test_0, CPPTEST_TIMEOUT);

C++test will then expect that timeout is the expected result for the test case "test_0".

CPPTEST_TEST_FAIL(testCaseName)Used to specify that the given test case is expected to fail for some reason (e.g., an exception, timeout, failed assertion etc.). Since this macro does not  allow you to specify the exact reason of the failure, it is better to use CPPTEST_TEST_ERROR() or
CPPTEST_TEST_EXCEPTION() whenever possible.
CPPTEST_TEST_DS(testCaseName, dsDefinition)

Used to register a test case that uses data from the given data source. The following macros can be used to define the data source:

CPPTEST_DS(dsName) - To use a managed data source with the given name.

CPPTEST_DS_ARRAY(ARRAY_NAME, ROW, COLUMN) - To use ARRAY_NAME as a data source. ARRAY_NAME should be defined in the source as const char* ARRAY_NAME[ROW][COLUMN]. The first row of the array must contain columns names. The test case will be executed (ROW - 1) times.

CPPTEST_DS_CSV(FILE_NAME, SEPARATOR, HAS_HEADER, TRIM) - To use data from the comma separated values file. Macro parameters are:

FILE_NAME  - Name of the data source file with the data source. It may be specified with a full or relative file path.
Note: If a relative path is used, it's relative to the test executable’s  working directory, which can be customized in the Test Configurations’s Test executable run directory. field (in the Execution> Runtime tab). 

SEPARATOR  - Field separator. It should be specified as a character constant (ex: ',').

HAS_HEADER - If the first record (row) is a header, this should be set to 1. Otherwise, it should be set to 0.
Note: If there is no header in the CSV file, then each column name is its ordinal number (starting with 0). 

TRIM - If spaces before/after a value should be omitted, this should be set to 1. Otherwise, it should be set to 0.

CPPTEST_DS_REPEAT(NUMBER) - To make C++test execute the given test case NUMBER of times.

CPPTEST_TEST_DISABLED(testcasename)Registration of a disabled test case - it will not be executed.
CPPTEST_TEST_EXCEPTION_DISABLED(testcasename, ExceptionType)Registration of a disabled test case - it will not be executed.
CPPTEST_TEST_ERROR_DISABLED(testcasename, ErrorCode)Registration of a disabled test case - it will not be executed.
CPPTEST_TEST_FAIL_DISABLED(testcasename)Registration of a disabled test case - it will not be executed.
CPPTEST_TEST_SUITE_REGISTRATION(TestSuiteName)Registers test suite for execution. Has to be placed in the test suite source file.
CPPTEST_CONTEXT(testedFile)Using this macro in the test suite source code defines the given test suite tests’ specified source / header file.
CPPTEST_TEST_SUITE_INCLUDED_TO(tested Source)Using this macro in the test suite source code specifies that the given test suite will be appended to the end of the given source file when the test executable is built.
  • No labels