MATLAB: Don’t I get full coverage for the model even though each subsystem has full coverage

Simulink Coveragesimulink test

I have created test harnesses for each subsystem in my model (referred to as unit tests), and I have ensured that the tests for each subsystem test harness achieve full coverage. Then I run coverage analysis on my top level model and I am not getting full coverage, even though each individual subsystem has full coverage. Why don't I get full coverage for my top level model even though all my subsystems have full coverage?

Best Answer

Based on the definition of coverage provided here,

https://www.mathworks.com/help/releases/R2020a/slcoverage/ug/model-coverage.html

your system level tests need to fully exercise all simulation pathways in the model to obtain full coverage. There is no way to make your unit tests contribute to coverage for the top level model. This ensures that the units that have been integrated into the system are tested within the context of that system.

On the other hand, if you only want to measure the degree to which the model has been tested (including unit tests), then there is a way to create a report for that. This is called Unit-Test Aggregation:

https://www.mathworks.com/help/releases/R2020a/slcoverage/ug/trace-coverage-results-to-associated-test-cases.html#mw_2cd0624d-19f8-4c46-b366-00d3fd37a269

The example above illustrates that you can create a report that shows aggregated coverage that includes results from both integration and unit tests.

Related Question