%% Include Test Manager Results in MATLAB Unit Test Results
% This example shows how to include Test Manager Results in a TestResult object produced through the MATLAB Unit Test framework.
% The test case creates a square wave input to a controller subsystem and sweeps through 25 iterations of parameters a and b. The test compares the alpha output to a baseline with a tolerance of 0.0046. Output that exceeds this tolerance fails the test.
%
% 1. Set the path to the test file.

testfile = 'f14ParameterSweepTest.mldatx';

%
% 2. Create the TestSuite object.

import matlab.unittest.TestSuite
suite = testsuite(testfile);

%
% 3. Create the TestRunner object.

import matlab.unittest.TestRunner
runner = TestRunner.withNoPlugins;

%
% 4. Add the TestManagerResultsPlugin to the TestRunner.

tmr = sltest.plugins.TestManagerResultsPlugin; 
addPlugin(runner,tmr)

%
% 5. Run the test.

results = run(runner,suite);

%
% 6. View results of 19th iteration, a test failure.

failure = results(19)

% In the Details field of the TestResult object, test Iteration results appear as a SimulinkTestManagerResults object. The SimulinkTestManagerResults object contains information such as the type of test case, the cause of the failure, and the values of the parameters that led to the failure.

failure.Details.SimulinkTestManagerResults.TestCaseType
failure.Details.SimulinkTestManagerResults.CauseOfFailure
failure.Details.SimulinkTestManagerResults.IterationSettings.variableParameters(1)
failure.Details.SimulinkTestManagerResults.IterationSettings.variableParameters(2)

%
% Copyright 2020 The MathWorks, Inc.