Main Content
Incorrect use of mocking API
Description
This defect occurs when you invoke the mock function selector PST_SELECT_MOCK
outside a test body, for instance, in a test configuration.
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
All selected mock functions get reset before a test is run. If you select a mock outside a test body, the mock does not get used in the test.
Fix
Move the PST_SELECT_MOCK
statement inside a test body, that is, inside a PST_TEST_BODY
block.
Examples
Result Information
Group: Libraries Misuse |
Language: C | C++ |
Default: Off |
Command-Line Syntax: PSTUNIT_MISUSE_MOCKING |
Impact: Medium |
Version History
Introduced in R2023b