C/C++test can send the results of test executed with Google Test to DTP, as well as generate a local HTML report using the XML report created by the test framework.
Reporting Google Test Results
Add the following option to your normal Google Test test driver command:
--gtest_output=xml:<result_filename>.xml
A Google Test result XML file is generated
Run the following test configuration and specify the Google Test result XML file as the input (see Configuring Test Configurations for additional information about test configurations):
cpptestcli -config builtin://GoogleTest -input <result_filename>.xml -publish
This will generate an HTML report, as well as send test results to DTP server if configured (see Connecting to DTP for additional information).
C/C++test will perform the following actions:
- Associate the test results with the project name specified with the
dtp.projec
t property - Associate test failures with the author specified with the
dtp.user
property
Improving the Test Case File Association
The Google Test result XML file provides limited information and may incorrectly associate passed test cases with the tested file. This may affect how test results are displayed in some DTP Test widgets. Use the RecordProperty
function inside a test case to force an association between a test case and a file. Use cpptest_filename
as the attribute name and the filename as the second argument:
TEST(ExampleTestSuite, ExampleTestCase) { RecordProperty("cpptest_filename", __FILE__); }
The RecordProperty
function is provided by the Google Test framework.
Associating Tests with Code Coverage
You can automatically annotate code coverage results with test start/stop information (see Annotating Results with Test Start and Stop Information). This will allow you to selectively analyze code coverage generated by a specific test or collection of tests.
Include a dedicated header file in the source file that contains Google Test main function:
#include "cpptest/gtest.h"
Add the following code to the main function after the InitGoogleTest() call and before tests execution:
CppTest_GoogleTestListener::Append();
Alternatively, you can register the C++test listener using the GoogleTest API directly:
::testing::TestEventListeners& listeners = ::testing::UnitTest::GetInstance()->listeners(); listeners.Append(new CppTest_GoogleTestListener());
For simple setups, your modified main function may resemble the following:
GTEST_API_ int main(int argc, char **argv) { // Initializing GoogleTest testing::InitGoogleTest(&argc, argv); // Appending CppTest_GoogleTestListener CppTest_GoogleTestListener::Append(); // Running tests return RUN_ALL_TESTS(); }
Use the
-I
option to specify the cpptest/gtest.h header file location when compiling the source file with the main function:-I <Installation Directory>/runtime/include
- Build test executable as described in Collecting Code Coverage.
Run the test executable with the following option:
--gtest_output=xml:<result_filename>.xml
Run cpptestcli specifying the GoogleTest result .xml file and coverage log file as the inputs to generate a report:
cpptestcli -config builtin://GoogleTest -input <result_filename>.xml -input cpptest_results.clog -publish
See Reviewing Results for details on configuring and publishing reports.