perform functional testing and analyze test coverage
functional testing begins with building test cases based on requirements. these tests can cover key aspects of your design and verify that individual model components meet requirements. test cases include inputs, expected outputs, and acceptance criteria.
by collecting individual test cases within test suites, you can run functional tests systematically. to check for regression, add baseline criteria to the test cases and test the model iteratively. coverage measurement reflects the extent to which these tests have fully exercised the model. coverage measurement also helps you to add tests and requirements to meet coverage targets.
incrementally increase test coverage using test case generation
this example shows how to perform requirements-based tests for a cruise control model. the tests link to a requirements document. you:
run the tests.
determine test coverage by using simulink® coverage™.
increase coverage with additional tests generated by simulink design verifier™.
report the results.
open the test harness and model
open the project:
openexample("shared_vnv/cruisecontrolverificationprojectexample"); pr = openproject("simulinkverificationcruise");
open the model and the test harness. at the command line, enter:
open_system simulinkcruiseaddreqexample sltest.harness.open("simulinkcruiseaddreqexample","safetytest_harness1")
load the test suite from (simulink test) and open the simulink test manager.
pf = fullfile(pr.rootfolder,"tests","slreqtests.mldatx"); tf = sltest.testmanager.testfile(pf); sltest.testmanager.view
open the test sequence block. the sequence verifies system disengagement when either:
the brake pedal is pressed.
speed exceeds a limit.
measure model coverage
in the simulink test manager, select the
slreqtests
test file.to enable coverage collection, in the right page under coverage settings:
select record coverage for referenced models.
specify a coverage filter by using coverage filter filename.
select decision, condition, and mcdc.
click run on the test manager toolstrip.
after the test completes, select results. the test achieves 50% decision coverage, 41% condition coverage, and 25% mcdc coverage.
generate tests to increase model coverage
use simulink design verifier to generate additional tests to increase model coverage. in results and artifacts, select the
slreqtests
test file and open the aggregated coverage results section located in the right pane.right-click the test results and select add tests for missing coverage.
under harness, choose
create a new harness
.click ok to add tests to the test suite using simulink design verifier. the model being tested must either be on the matlab® path or in the working folder.
on the test manager toolstrip, click run to execute the updated test suite. the test results include coverage for the combined test case inputs, achieving increased model coverage.
alternatively, you can create and use tests to increase coverage programmatically by using (simulink test) and (simulink test).
related topics
- (simulink test)
- (simulink test)
- (simulink test)
- (simulink design verifier)
- (simulink test)