Main Content

sltest.plugins.TestManagerResultsPlugin class

Package:sltest.plugins

Generate enhanced test results with theMATLABUnit Test framework

Description

Use thesltest.plugins.TestManagerResultsPluginclass to include Test Manager results when using the MATLAB®Unit Test framework to run金宝app®Test™files. Test Case and Test Iteration results appear in theDetailsfield of eachTestResultobject.

To publish Test Manager results, configure your test file for reporting and add theTestReportPluginandTestManagerResultsPluginclasses to theTestRunnerobject. Test Case and Test Iteration results appear in theDetailssection of the MATLAB Test Report. For more information, seeTest a Model for Continuous Integration Systems.

Creation

tmr= sltest.plugins.TestManagerResultsPlugincreates ansltest.plugins.TestManagerResultsPluginplugin objecttmr. You use the plugin object only to direct theTestRunnerto produce an enhanced test result.

You can also import the plugin, and then use the class name to create the object:

import sltest.plugins.TestManagerResultsPlugin tmr = TestManagerResultsPlugin

Input Arguments

expand all

Name-Value Arguments

Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN, whereNameis the argument name andValue相应的价值。名称-值参数must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and encloseNamein quotes.

Example:'ExportToFile','myfile'

Optional file to save results inSimulink TestMLDATX format, specified as the comma-separate pair consisting of'ExportToFile'and the file name.

You can open the MLDATX results file in the Test Manager by clicking theImportbutton on the toolbar.

Example:'ExportToFile','myfile'

Example:'ExportToFile','myfile.mldatx'

Examples

collapse all

This example shows how to include Test Manager Results in aTestResultobject 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 parametersaandb. The test compares thealphaoutput to a baseline with a tolerance of0.0046. Output that exceeds this tolerance fails the test.

1.设置测试文件的路径。

testfile ='f14ParameterSweepTest.mldatx';

2. Create theTestSuiteobject.

importmatlab.unittest.TestSuitesuite = testsuite(testfile);

3. Create theTestRunnerobject.

importmatlab.unittest.TestRunnerrunner = TestRunner.withNoPlugins;

4. Add theTestManagerResultsPluginto theTestRunner.

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)
failure = TestResult with properties: Name: 'f14ParameterSweepTest > New Test Suite 1/Iterations Parameter Sweep(ScriptedIteration=Scripted_Iteration19)' Passed: 0 Failed: 1 Incomplete: 0 Duration: 0.6965 Details: [1x1 struct] Totals: 0 Passed, 1 Failed, 0 Incomplete. 0.69645 seconds testing time.

In theDetailsfield of theTestResultobject, test Iteration results appear as aSimulinkTestManagerResultsobject. TheSimulinkTestManagerResultsobject 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
ans = 'Baseline Test'
failure.Details.SimulinkTestManagerResults.CauseOfFailure
ans = 'Failed criteria: Baseline'
failure.Details.SimulinkTestManagerResults.IterationSettings.variableParameters(1)
ans =struct with fields:parameterName: 'a' source: 'base workspace' value: 2.6000 displayValue: '2.6' simulationIndex: 1
failure.Details.SimulinkTestManagerResults.IterationSettings.variableParameters(2)
ans =struct with fields:parameterName: 'b' source: 'base workspace' value: 66 displayValue: '66' simulationIndex: 1

版本历史

Introduced in R2018b