Generate Coverage Results for Models
You can use Simulink® Coverage™ to determine how much of your model executes during simulation, and identify gaps in your testing. There are multiple ways to generate coverage results for a model:
Simulate your model using the Run button.
Run your model multiple time using the Multiple Simulations pane and Run (All) button.
Create a test suite using the Test Manager in Simulink Test™.
Create and run test cases programmatically.
Run Single Simulations Interactively in Simulink
If you select the Enable coverage analysis parameter In the Configuration Parameters dialog box and then simulate your model using the Run (Coverage) button, Simulink Coverage opens the Coverage Details pane, which contains the coverage report, highlights each block or chart in your model, and indicates how each object performed in the coverage analysis. Use the Run (Coverage) button when you want to highlight the blocks in your model, or if you want to create coverage filters for unsatisfied coverage objectives. For more information, see Basic Operation of the Model Coverage Tool and View Coverage Results in Simulink Canvas.
Run Simultaneous Simulations in Simulink Using Multiple Simulations Pane
You can use the Multiple Simulations pane to collect coverage for two or more simulations. In Simulink, on the Simulation tab, under Prepare, click Multiple Simulations. In this pane, you can create design studies, add simulation scenarios, and then run all the scenarios in series. If you have Parallel Computing Toolbox™, the simulations run in parallel. For more information, see Collect Coverage for Multiple Simulations by Using Design Studies.
Run Tests Using the Test Manager in Simulink Test
If you have a Simulink Test license, you can use the Test Manager to author and run test scenarios. In your test file, under Coverage Settings, select Record coverage for system under test. Then select the coverage metrics you want to analyze. When you collect coverage this way, the Test Manager shows the coverage summary for your tests under the Aggregated Coverage Results section. If you click the model name in the coverage summary, it highlights your model with those coverage results.
Use the Test Manager when you want to perform requirements-based testing by scoping your coverage results to linked requirements, or if you want to perform back-to-back testing to analyze consistency between your model and generated code. For more information, see Analyze Model Coverage by Using the Test Manager in Simulink Test and Assess Coverage Results from Requirements-Based Tests.
Analyze Coverage Programmatically
You can analyze coverage by using the Simulink Coverage or Test Manager API. The API you use depends on what product licenses you have or what tools you are already using. For example, if you already use the Test Manager in Simulink Test, then consider using the Test Manager API for your test automation.
Use the Simulink Coverage API
You can collect coverage data programmatically by using
Simulink.SimulationInput objects. For more information, see
Collect Coverage Data Using a Script and
Perform Operations on Coverage Data.
Use the Test Manager API
The Test Manager in Simulink Test also includes an API that you can use to automate testing. You can enable coverage, scope your coverage results to linked requirements, run tests, and create reports. For more information, see Create and Run Test Cases with Scripts (Simulink Test) and Run a Test Case and Collect Coverage (Simulink Test).