Add tests to increase coverage
Add Tests for Missing Coverage to Existing Test Case
This example shows how increase coverage when coverage results for a test case are lower than 100%.
Get the existing test case from the test file and then run the test and get the coverage data. Create a
TestOptions object and add missing coverage to the coverage data for new test case. Run the new test case and open the Test Manager.
load_system("CruiseControlAddCov.slx"); tf = sltest.testmanager.TestFile('CruiseControlAddCov.mldatx'); ts = getTestSuites(tf); testcaseObj = getTestCases(ts); tr = run(testcaseObj); cvdata = getCoverageResults(tr); testOpts = sltest.testmanager.TestOptions(testcaseObj); newTestCaseObj = sltest.testmanager.addTestsForMissingCoverage... (testOpts,cvdata); tr = run(newTestCaseObj); sltest.testmanager.view;
In the Results and Artifacts panel in the Test Manager, select the first Results. In the Aggregated Coverage Results section, the coverage is less than 100%.
Now, select the second Results. In the Aggregated Coverage Results section, the coverage increased to 100%.
Clear and close the Test Manager.
sltest.testmanager.clear sltest.testmanager.clearResults sltest.testmanager.close
testOpts — Options to use when adding for adding missing coverage
Options to use when adding coverage to a test case, specified as a
cvData — Coverage data
Coverage data, specified as the path to the
cvdata object from
the test with missing coverage. For example, suppose that you have a test case,
tc, that you run to get the coverage data from the test results,
getcoverageResults to get the coverage
tr = tc.run(); cvdata = tr.getCoverageResults;
Introduced in R2022a