Test Authoring Using C/C++ xUnit API
You can author tests for C/C++ code by using the Polyspace® Test™ API. The API follows the specifications of the xUnit framework for testing and supports features such as test cases and test suites with common setup and teardown functions.
The Polyspace Test xUnit API consists of function-like macros (C and C++) and test classes (C++ only) defined in files that are available with a Polyspace Test installation. To test your C/C++ code using the API:
Write tests that invoke these macros or inherit from these classes.
Build your tests and sources along with the Polyspace Test macro or class definition files by using your existing toolchain. Alternatively, you can add your sources and tests to a Polyspace Platform project, and build and execute them through this project.
System Commands
polyspace-test -generate | (System Command) Generate test registration function from a set of Polyspace Test C/C++ test files |
Topics
Getting Started
- Set Up C/C++ Testing and Code Profiling Using Self-Managed Builds
Define environment variables that point to locations of Polyspace Test files required for compiling xUnit tests or code profiling macros. - Write C/C++ Unit Tests Using Polyspace Test xUnit API and Run Tests at Command Line
Get started with writing xUnit-based C/C++ tests using predefined macros from the Polyspace Test API.
Creating Tests
- Writing Tests Using Polyspace Test xUnit API for C/C++ Code
Look up the various test creation macros that you can use in tests written with the Polyspace Test API. - Configuration Macros in Polyspace Test API for C/C++ Code
Look up the configuration macros that you can use to configure the behavior of the test executable. - Write C/C++ Tests with Known Errors or Failures to Support Test-Driven Development
Write tests with expected failures or errors by including specific build-configuration-dependent macros.
Writing Assessments
- Assessment Macros in Polyspace Test API for C/C++ Code
Look up the various assessment macros that you can use in tests written with the Polyspace Test API. - Choose Assessment Macro Variant in Polyspace Test xUnit API
Choose betweenPST_VERIFY,PST_VERIFY_EQandPST_VERIFY_EQ_MSGmacros.
Grouping Tests
- Group C/C++ Tests into Suites with Common Setup and Teardown Code
Avoid duplication and improve consistency in test setup with setup code that runs for all tests in a suite. - Write Test Fixtures Using Polyspace Test C++ API
Use a test fixture to share test context between tests.
Parametrizing Tests
- Write Parameterized Tests for C/C++ Functions Using Polyspace Test xUnit API
Test a function for several combinations of input values. - Test Multi-Input C/C++ Functions Using Multiple Parameters and Parameter Combination Strategies
Test multi-input functions using parameterized tests with multiple parameters, run through parameter value combinations sequentially or exhaustively.
Range Specification
- Range Specification Macros in Polyspace Test xUnit API
Look up the various range specification macros that you can use in tests written with the Polyspace Test API. - Test Functions and Constrain Polyspace Code Prover Analysis for Ranges of Inputs and Outputs
Test functions over one or more ranges of input and verify if the output is within a valid range using range specification macros. Run static analysis on the function and associated tests using the specified ranges as external constraint. - Test Functions That Operate on Arrays Using Range Specification Macros
Create array inputs for functions that operate on arrays and test if elements of the output array are within a specified range.
Adding to Polyspace Platform Projects
- Add C/C++ xUnit Tests to Projects in Polyspace Platform User Interface
Write tests using Polyspace Test xUnit API and execute them from Polyspace Platform user interface. - Link C/C++ Sources and Tests to Requirements
Create links from sources and tests in a Polyspace Platform project to requirements authored in an external editor or requirements management tool.