sltest.plugins.coverage.CoverageMetrics Class
Namespace: sltest.plugins.coverage
Specify coverage metrics for tests run with MATLAB Unit Test framework
Description
Use the sltest.plugins.coverage.CoverageMetrics
class to specify
coverage metrics. Pass the coverage metrics object to the model coverage plugin
object.
The sltest.plugins.coverage.CoverageMetrics
class is a handle
class.
Creation
creates a coverage metrics object with specified properties.cmo
= sltest.plugins.coverage.CoverageMetrics(Properties
)
You can also import the plugin, then use the class name to create the object:
import sltest.plugins.coverage.CoverageMetrics
cmo = CoverageMetrics(Properties)
Properties
Decision
— Decision coverage
true (default) | false
Enable or disable decision coverage collection.
Example: 'Decision',true
Attributes:
SetAccess | public |
GetAccess | public |
Condition
— Condition coverage
false (default) | true
Enable or disable condition coverage collection. If you enable Condition coverage, the Coverage Report shows both Condition and Decision coverage.
Example: 'Condition',true
Attributes:
SetAccess | public |
GetAccess | public |
MCDC
— MCDC coverage
false (default) | true
Enable or disable modified condition/decision coverage collection. If you enable MCDC, Condition and Decision coverage are also collected and are included in the Coverage Report.
Example: 'MCDC',true
Attributes:
SetAccess | public |
GetAccess | public |
LookupTable
— Lookup table coverage
false (default) | true
Enable or disable lookup table coverage collection.
Example: 'LookupTable',true
Attributes:
SetAccess | public |
GetAccess | public |
SignalRange
— Signal range coverage
false (default) | true
Enable or disable signal range coverage collection.
Example: 'SignalRange',true
Attributes:
SetAccess | public |
GetAccess | public |
SignalSize
— Signal size coverage
false (default) | true
Enable or disable signal size coverage collection.
Example: 'SignalSize',true
Attributes:
SetAccess | public |
GetAccess | public |
SimulinkDesignVerifier
— Simulink Design Verifier block coverage
false (default) | true
Enable or disable Simulink Design Verifier block coverage collection.
Example: 'SimulinkDesignVerifier',true
Attributes:
SetAccess | public |
GetAccess | public |
SaturationOnIntegerOverflow
— Block saturation on integer overflow
false (default) | true
Enable or disable recording the number of times the block saturates on integer overflow.
Example: 'SaturationOnIntegerOverflow',true
Attributes:
SetAccess | public |
GetAccess | public |
RelationalBoundary
— Relational boundary coverage
false (default) | true
Enable or disable relational boundary coverage.
Example: 'RelationalBoundary',true
Attributes:
SetAccess | public |
GetAccess | public |
Examples
Collect Model Coverage Using the MATLAB® Unit Testing Framework
This example shows how to use the MATLAB® unit testing framework to collect coverage for tests run on a Simulink® model.
You run the tests in the AutopilotTestFile.mldatx
test file while collecting modified condition/decision (MCDC) coverage.
1. Import the test runner and the plugins for the example.
import matlab.unittest.TestRunner import sltest.plugins.ModelCoveragePlugin import sltest.plugins.coverage.CoverageMetrics import sltest.plugins.coverage.ModelCoverageReport import matlab.unittest.plugins.codecoverage.CoberturaFormat
2. Create a subfolder in the current working directory and create a ModelCoverageReport
object specifying that new folder.
mkdir('./myReports/coverage'); path = './myReports/coverage'; mcr = ModelCoverageReport(path,'ReportName','RollRefCov');
3. Create the model coverage plugin object and the coverage metrics object. In this example, you use MCDC coverage and record coverage for referenced models.
mcdcMet = CoverageMetrics('Decision',true,'Condition',true,'MCDC',true); covSettings = ModelCoveragePlugin('RecordModelReferenceCoverage',true,... 'Collecting',mcdcMet,'Producing',mcr);
4. Create a MATLAB® Unit Test test suite from the test file.
tf = sltest.testmanager.TestFile('AutopilotTestFile.mldatx');
APSuite = testsuite(tf.FilePath);
5. Create the test runner without any plugins, then add the coverage plugin to the runner.
APRun = TestRunner.withNoPlugins(); addPlugin(APRun,covSettings);
6. Run the suite.
% Turn off the command line warnings. warning off Stateflow:cdr:VerifyDangerousComparison warning off Stateflow:Runtime:TestVerificationFailed APResult = run(APRun,APSuite)
Coverage Report for RollAutopilotMdlRef/Roll Reference /tmp/Bdoc24b_2679053_1875008/tp29e4a166/simulinktest-ex63642652/myReports/coverage/RollRefCov.html
APResult = TestResult with properties: Name: 'AutopilotTestFile > Basic Design Test Cases/Requirement 1.3 Test' Passed: 1 Failed: 0 Incomplete: 0 Duration: 10.2058 Details: [1x1 struct] Totals: 1 Passed, 0 Failed, 0 Incomplete. 10.2058 seconds testing time.
7. You can open the link in the command-line output to view the coverage report.
8. You can also create a report in Cobertura XML format. Create a new test runner with no plugins, add the ModelCoveragePlugin, and run the test suite. The Cobertura report is saved to the working folder.
CobRun = TestRunner.withNoPlugins; addPlugin(CobRun,ModelCoveragePlugin('Producing',... CoberturaFormat('CoverageResults.xml'))); CobResult = run(CobRun,APSuite);
Cleanup. Clear results and re-enable warnings.
warning on Stateflow:cdr:VerifyDangerousComparison warning on Stateflow:Runtime:TestVerificationFailed sltest.testmanager.clearResults; sltest.testmanager.clear; sltest.testmanager.close;
Version History
Introduced in R2018a
See Also
sltest.plugins.ModelCoveragePlugin
| sltest.plugins.coverage.ModelCoverageReport
Topics
- Test Models Using MATLAB Unit Test
- Types of Model Coverage (Simulink Coverage)
- Model Objects That Receive Coverage (Simulink Coverage)
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)