%% Aggregate Unit-Level Coverage Data into Top-Level Model Coverage
% This example shows how to generate an aggregated coverage report that
% includes results from both integration and unit tests.

% Copyright 2019 The MathWorks, Inc.

%% Load the Test Cases into the Simulink&reg; Test&trade; Manager
% The |slcovTestTraceabilityExample.mldatx| test data is configured to
% record decision coverage.
sltest.testmanager.load('slcovTestTraceabilityExample.mldatx');
sltest.testmanager.view

%% Run the Test Cases
% From the Simulink Test Manager, select the |Combined Integration and Unit
% Tests| test suite and click *Run*. This test suite contains two
% sub-suites, |Integration Tests| and |Unit Tests|. Alternatively, run the
% following command:
results = sltest.testmanager.run;

%% Access the Coverage Report for the Integration Tests
% From the *Results and Artifacts* pane of the Simulink Test Manager,
% select the results for |Integration Tests|. From the *Aggregated Coverage
% Results* section, click the *Report* button.
% 
% The coverage report for this test suite only shows coverage results for the
% integration tests.
%%
% <<../aggregated_integration_tests.png>>

%% View Subsystem Details
% View the coverage details for the subsystem SwitchUnit2. Notice that this
% subsystem does not receive full coverage. The first three decision
% outcomes are covered by integration test run |T1|. The fourth decision
% outcome for the MPSwitch
%  block cannot be satisfied in the integrated system.
%%
% 
% <<../MP_switch_integration.png>>
% 

%% Access the Coverage Report for the Unit Tests 
% From the *Results and Artifacts* pane of the Simulink Test Manager,
% select the results for |Unit Tests|. From the *Aggregated Coverage Results* section, click the *Report* button.
% 
% The coverage report for this test suite only shows coverage results for the
% unit tests of the SwitchUnit2 subsystem that were recorded by using subsystem test harnesses.
%%
% <<../aggregated_unit_tests.png>>

%% View Subsystem Details
% View the coverage details for the subsystem SwitchUnit2. Notice that this subsystem does receive full
% coverage from the unit tests.
%%
% 
% <<../MP_switch_unit.png>>
% 

%% Locate the Combined Unit-Level and System-Level Coverage Report
% From the *Results and Artifacts* pane of the Simulink Test Manager,
% select the results for |Combined Integration and Unit Tests|. The results
% show two coverage reports available--one report for the SwitchUnit2
% subsystem tested by the unit tests and one report for the top-level model
% that incorporates results from both the unit and integration tests.
%%
% <<../aggregated_results_reports.png>>

%% Access Aggregated Coverage Report for the Top-Level Model
% When you click the *Report* button for the top-level model, Simulink Coverage aggregates the integration and unit
% tests into a system-level coverage report.
%%
% <<../aggregated_integration_and_unit_report.png>>

%% View Subsystem Details 
% Notice that the subsystem receives full coverage. The first three decision outcomes for the MPSwitch
% MultiPortSwitch block are covered by the integration test run |T1|. The fourth decision outcome for the MPSwitch
% MultiPortSwitch block is covered by unit test run |U1.2|.
%%
% <<../MP_switch_aggregate.png>>