%% Set Model Coverage Report Properties for MATLAB Unit Test
%
% This example shows how to specify model coverage report properties when running a Simulink® Test™ test file with MATLAB® Unit Test.
% To run the example, set the current folder to a writable folder.
%
%
%% 1. Import classes for the example.

import matlab.unittest.TestSuite
import matlab.unittest.TestRunner
import sltest.plugins.ModelCoveragePlugin
import sltest.plugins.coverage.ModelCoverageReport

%
%% 2. Create a test suite and test runner.
% Create a MATLAB Unit Test suite from AutopilotTestFile. Also create a test runner.

ste = testsuite('AutopilotTestFile.mldatx');
trn = TestRunner.withNoPlugins;

%
%% 3. Specify the report location.
% Create a subfolder in the current folder, and create a ModelCoverageReport object specifying the new folder.

mkdir('./exReports/coverage');
path = './exReports/coverage';
mcr = ModelCoverageReport(path)

%
%% 4. Create a Model Coverage Plugin.
% Use the Producing property to specify the ModelCoverageReport when creating the plugin.

mc = ModelCoveragePlugin('Producing',mcr)

%
%% 5. Add the coverage plugin to the test runner, and run the test.

addPlugin(trn,mc);

% Turn off the command line warnings.
warning off Stateflow:cdr:VerifyDangerousComparison
warning off Stateflow:Runtime:TestVerificationFailed

run(trn,ste)

%
%
%
%% Cleanup. Remove temporary folder and clear variables. Enable warnings.

warning on Stateflow:cdr:VerifyDangerousComparison
warning on Stateflow:Runtime:TestVerificationFailed

rmdir('./exReports','s');
clear('ste','trn','fldr','path','mcr','mc');

%
% Copyright 2018 The MathWorks, Inc.