Incorrect use of test setup/teardown API
Test setup invoked in test suite configuration, suite setup invoked in test configuration, and so on
Since R2023b
Description
This defect occurs when you invoke setup and teardown macros from the Polyspace® Test™ xUnit API in the incorrect configuration. For instance:
You invoke suite-level macros such as
PST_SUITE_SETUPorPST_SUITE_TEST_SETUPin the test configuration macroPST_TEST_CONFIG(instead of the suite configuration macroPST_SUITE_CONFIG).You invoke test-level macros such as
PST_SETUPin the suite configuration macroPST_SUITE_CONFIG(instead of the test configuration macroPST_TEST_CONFIG).
Similar considerations apply to teardown macros PST_SUITE_TEARDOWN, PST_SUITE_TEST_TEARDOWN and PST_TEARDOWN.
This checker is enabled if you specify the value pstunit for the option Libraries used (-library) or find defects in a test file from the Polyspace Platform (Polyspace Test) user interface. For more
information, see Check for Bugs and Run-Time Errors in C/C++ Tests and Functions Under Test (Polyspace Test).
Risk
When you run tests, setup and teardown macros invoked in the incorrect configuration get ignored. As a result, your tests are not set up correctly.
Fix
Invoke test setup and teardown macros in the correct configuration.
| Setup and Teardown Macro | Configuration |
|---|---|
| PST_SUITE_CONFIG |
| PST_TEST_CONFIG |
Examples
Result Information
| Group: Libraries Misuse |
| Language: C | C++ |
| Default: Off |
Command-Line Syntax: PSTUNIT_MISUSE_SETUP_TEARDOWN |
| Impact: Medium |
Version History
Introduced in R2023b
See Also
Find defects (-checkers) | Libraries used (-library)
Topics
- Group C/C++ Tests into Suites with Common Setup and Teardown Code (Polyspace Test)