Execute C/C++ Tests Written Using Polyspace Test xUnit API
You can write C/C++ unit tests using the Polyspace® Test™ xUnit API and build them using your own compilation toolchain. When you build these tests, you create a test runner executable that can be used to run the tests later. The test runner executable prints test results (test pass/fail information) on the console. You can optionally pipe the console output to a file for further processing.
This topic shows the various options available for test execution. To see the list of options available for test execution, at the command line, enter the following:
testRunner -h
testRunner is the test runner executable, for example, the executable testrunner.exe created in Write C/C++ Unit Tests Using Polyspace Test xUnit API and Run Tests at Command Line. This topic goes over some of the options that you see in the list.Prerequisites
This topic describes test authoring using the Polyspace Test xUnit API. To compile these tests, you are required to know some file paths in advance. For your convenience, you can define environment variables to stand for the file paths, or otherwise include the file paths in your build. For more information, see Set Up C/C++ Testing and Code Profiling Using Self-Managed Builds.
Execute Specific Tests
If you run the test executable without additional options, all tests are executed.testRunner
To run a test that is not part of a test suite, add the option
-testfollowed by the test name. For example, to run the testmyTest, enter:Enter multiple test names separated by comma-s. For example, to run the teststestRunner -test myTest
myTest1andmyTest2, enter:testRunner -test myTest1,myTest2
To run tests in a specific suite, add the option
-testfollowed by the suite name. For example, to run all tests in the suitemySuite, enter:To run a specific test in a specific suite, add the optiontestRunner -test mySuite
-testfollowed by the suite and test name, separated by a/. For example, to run a testmyTestin the suitemySuite, enter:For more information on test suites, see Group C/C++ Tests into Suites with Common Setup and Teardown Code.testRunner -test mySuite/myTest
To run a parameterized test with specific values of the test parameters, add the option
-testfollowed by the comma-separated parameter value numbers in parenthesis.For example, suppose a test
myTestin themySuitehas two parameters:param1takes its values from the arraydata1.param2takes its values from the arraydata2.
To run this test with
param1taking the first value ofdata1andparam2taking the first value ofdata2, enter:testRunner -test mySuite/myTest(1,1)
For more information on parameterized tests, see:
Check for Test Execution Success
You can check the overall status of test execution by checking the exit code of the test runner executable. The exit code is 0 if all tests pass and 1 if at least one test fails or there is an error in test execution.
You can check the exit code in different ways on various operating systems. For instance,
On Windows®, you can check the exit code of the last executed command as follows:
echo %ERRORLEVEL%
On Linux®, you can check the exit code of the last executed command as follows:
echo $?
Define Test Results Format
By default, the test runner executable displays results in a human-readable tabular format and shows assessment details only for failing tests. You can change the result format using the option -format followed by a comma-separated list of arguments.
For example, to display results in the Test Anything Protocol (TAP) format and log assessments for passing tests, enter:
testRunner -format tap,passed
For more information, see Results Format of Tests Written Using Polyspace Test API.
You can also generate test results in the .pstestr format and open the results in the Polyspace Platform user interface, or generate an HTML report from the test results. To generate results in this format, you have to follow these steps:
Generate results in an intermediate machine-readable (
.mrf) format using the test runner executable. You can either append the flag-format mrfto the test runner executable or define the configuration macroPST_OUTPUTas follows:#define PST_OUTPUT PST_OUTPUT_MRF
Generate a
.pstestrfile from this intermediate format using the commandpolyspace-test -convert. You can open this file in the Polyspace Platform user interface. See also Open Polyspace Results in Polyspace Platform User Interface.When generating the
.pstestrfile, you can add the option-compilation-working-dir. This option specifies the folder from which the compiler command was executed when creating the test runner. The compiler folder specification allows thecompileFolderpolyspace-testcommand to find the source files starting from Polyspace Test results.Generate an HTML report from this
.pstestrfile using the commandpolyspace-test -report.
For example, the following commands generate a file in the folder resultsFile.pstestr and then generate an HTML report from the results:resultsFolder
testRunner -format mrf > resultsFile.mrf polyspace-test -convert -results-dir resultsFolder resultsFile.mrf polyspace-test -report -report-dir reportFolder -html resultsFolder/resultsFile.pstestr
index.html in a subfolder of reportFolder. This file shows a breakdown of test results by test suite. You can click on links in this file to drill down to individual tests in the
suite.See Also
polyspace-test -report | polyspace-test -convert