Test Authoring Using C/C++ xUnit API
R2026bWrite tests using C or C++ macros, group tests into suites, parametrize tests
Author tests for C/C++ code by using the Polyspace® Test™ xUnit API. Group tests into suites, use assertion macros to verify expected behavior, and add setup and teardown functions for common initialization.
A test declares a suite and uses assertion macros to check results:
PST_SUITE(arith_operations);
PST_TEST(arith_operations, test_times_two) {
int result = times_two(3);
PST_ASSERT_EQ_INT(result, 6);
}Build your tests and sources along with the Polyspace Test header files by using your existing toolchain, or add them to a Polyspace Platform 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.
Release-Specific Changes
- Changes to Self-Managed Build Workflows in Polyspace Test in R2026b
Find all changes you need to make in your build scripts starting R2026b for self-managed builds using Polyspace Test.