In this section:
You can annotate code coverage results with test start/stop information to understand how a particular test scenario affects code execution. Test start notification conveys information about the test name, which can be used when processing test data and generating reports.
Test Start/Stop annotations functionality is available as an API and can be extended to many different scenarios. For example, you can associate code coverage results with unit tests or associate code coverage results with manual test scenarios performed during system testing.
The API includes the following functions:
void CDECL_CALL CppTest_TestStart(const char* testName)
- sends the notification to the results stream about the beginning of a test with a specified namevoid CDECL_CALL CppTest_TestStop(void)
- sends the notification to the results stream about the end of the previously started test. Include a dedicated header file in the source file that will invoke the API functions:
#include "cpptest/cpptest.h" |
Use the -I
option to specify the cpptest.h
header file location when compiling the source file:
-I <Installation Directory>/runtime/include |
Specify a valid string as an argument to the CppTest_TestStart function
. Null pointers or invalid strings will cause undefined behavior.
The following scenarios illustrate the usage of the test start/stop notification API.
In this scenario, unit test case names are used as an argument specified to CppTest_TestStart
function invocation. For some of popular C/C++ unit testing frameworks, dedicated connectors are provided to automate this task. For additional information about unit testing framework connectors, see Unit Testing.
To use a unit testing framework that does not have a dedicated connector, you can invoke start/stop API functions at the beginning and end of the test case:
#include "cpptest/cpptest.h" TEST(TimerTest, smokeTest) { const char * tcName = testCaseName(); CppTest_TestStart(tcName); int res = init_timer(); ASSERT_TRUE(res != 0); CppTest_TestStop(); } |
There are a few ways to achieve this goal: