Test Scripts
You can use the Simulink® Test™ programmatic interface to:
Create test scripts and functions.
Run tests from the command line.
Set up and standardize your testing environment.
You can use scripts and functions to repeat the same test strategy on multiple systems, or perform regression testing. These functions and classes cover test authoring, execution, and results in Simulink Test. If you want to combine existing Simulink tests with MATLAB® tests, or run tests with continuous integration, use the MATLAB Unit Test Framework. See Continuous Integration. If you want to run tests on third-party test benches, see ASAM XIL Tests.
Simulink Test also provides graphical user interfaces to help you create and run tests. For more information, see Test Authoring, Test Execution, and Results, Reporting, and Test File Management.
Functions
Test Authoring
Test Files, Test Suites, and Test Cases
sltest.testmanager.TestFile | Create or modify test file |
sltest.testmanager.TestSuite | Create or modify test suite |
sltest.testmanager.TestCase | Create or modify test case |
sltest.testmanager.createTestForComponent | Create test cases and test harnesses for model or model components (Since R2020b) |
sltest.testmanager.createTestsFromModel | Generate test cases from a model |
sltest.testmanager.copyTests | Copy test cases or test suites to another location |
sltest.testmanager.moveTests | Move test cases or test suites to a new location |
sltest.testmanager.load | Load a test file in the Simulink Test manager |
sltest.testmanager.getTestFiles | Get test files open in the Test Manager |
sltest.testmanager.clear | Clear test files from the Test Manager |
sltest.testmanager.RunPlatforms | Test platform type (Since R2023b) |
Inputs
sltest.testmanager.TestInput | Add or modify test input |
sltest.import.sldvData | Create test cases from Simulink Design Verifier results |
sltest.io.SimulinkTestSpreadsheet | Read spreadsheet in format used by Simulink Test (Since R2021a) |
sltest.testmanager.registerTestAdapter | Register adapter to convert test data (Since R2022b) |
Outputs
sltest.testmanager.BaselineCriteria | Add or modify baseline criteria |
sltest.testmanager.EquivalenceCriteria | Add or modify equivalence criteria |
sltest.testmanager.SignalCriteria | Add or modify signal criteria |
sltest.testmanager.CustomCriteria | Add or modify custom criteria |
sltest.testmanager.LoggedSignal | Create or modify logged signals for use as simulation outputs |
sltest.testmanager.LoggedSignalSet | Create or modify a set of logged signals |
sltest.testmanager.OutputTrigger | Signal logging output start and stop triggers (Since R2023a) |
sltest.testmanager.OutputTriggerResult | Signal logging output trigger results (Since R2023a) |
sltest.testmanager.TriggerMode | Output trigger type (Since R2023a) |
Iterations
sltestiteration | Create test iteration |
sltest.testmanager.TestIteration | Create or modify test iteration |
sltest.testmanager.ParameterSet | Add or modify parameter set |
sltest.testmanager.ParameterOverride | Add or modify parameter override |
Observers
sltest.observer.observeElement | Observe model element (Since R2024b) |
sltest.observer.addObserverReference | Add Observer Reference block to top level of model (Since R2024b) |
sltest.observer.addObserverPort | Add Observer Port block to model or subsystem (Since R2024b) |
sltest.observer.configureObserverPort | Configure Observer Port block (Since R2024b) |
sltest.observer.setObserverModel | Link Observer Reference block to Observer model (Since R2024b) |
sltest.observer.getObservedModel | Get system model linked to Observer model (Since R2024b) |
sltest.observer.getObserverPorts | Get Observer Port blocks (Since R2024b) |
sltest.observer.getObserverMapping | Get Observer Port block mapping (Since R2024b) |
sltest.observer.moveToObserver | Add block to Observer model (Since R2024b) |
sltest.observer.promoteObserver | Copy Observer Reference block to top level of model (Since R2024b) |
Fault Sets
sltest.testmanager.FaultSet | Create or modify fault set (Since R2024a) |
sltest.testmanager.SpecifiedFault | Create or modify faults added to fault sets in tests (Since R2024a) |
sltest.testmanager.refreshFaults | Refresh list of faults available in specified model in Simulink Test Manager (Since R2024a) |
MATLAB-Based Simulink Tests
sltest.TestCase | Test case class for MATLAB-based Simulink tests (Since R2020b) |
loadSystem | Load model for MATLAB-based Simulink test (Since R2020b) |
simulate | Simulate model or Simulink.SimulationInput for MATLAB-based
Simulink test (Since R2020b) |
sltest.TestCase.forInteractiveUse | Create test case for interactive use (Since R2020b) |
createTemporaryFolder | Create temporary folder (Since R2020b) |
assumeSignalsMatch | Assume two data sets are equivalent (Since R2020b) |
assertSignalsMatch | Assert two data sets are equivalent (Since R2020b) |
fatalAssertSignalsMatch | Fatally assert two data sets are equivalent (Since R2020b) |
verifySignalsMatch | Verify two sets of data are equivalent (Since R2020b) |
sltest.harness.SimulationInput | Create test harness simulation input for MATLAB-based Simulink tests (Since R2020b) |
createSimulationInput | Create simulation input object (Since R2021a) |
addModelCoverage | Enable model coverage collection for Simulink tests (Since R2021a) |
addSimulinkTestResults | Enable pushing test results to Simulink Test Manager (Since R2021a) |
sltest.plugins.MATLABTestCaseIntegrationPlugin | Add simulation and test results for MATLAB-based Simulink tests to Test Manager (Since R2020b) |
sltest.plugins.ToTestManagerLog | Output stream to write text to Test Manager result Logs for MATLAB-based Simulink tests (Since R2020b) |
sltest.plugins.ModelCoveragePlugin | Collect model coverage using the MATLAB Unit Test framework |
Test Harnesses
sltest.harness.check | Compare component under test between harness model and main model |
sltest.harness.clone | Copy test harness |
sltest.harness.close | Close test harness |
sltest.harness.convert | Convert test harnesses between internal and external storage |
sltest.harness.create | Create test harnesses |
sltest.harness.setHarnessCreateDefaults | Customize default property values for test harness creation (Since R2021b) |
sltest.harness.getHarnessCreateDefaults | Get harness creation default values (Since R2021b) |
sltest.harness.delete | Delete test harness |
sltest.harness.export | Export test harness to Simulink model |
sltest.harness.find | Find test harnesses in model |
sltest.harness.import | Import Simulink model to test harness |
sltest.harness.load | Load test harness |
sltest.harness.move | Move test harness from linked instance to library block or to a different harness owner |
sltest.harness.open | Open test harness |
sltest.harness.push | Push test harness workspace entries and configuration set to model |
sltest.harness.rebuild | Rebuild test harness and update workspace entries and configuration parameter set based on main model |
sltest.harness.set | Change test harness property |
sltest.harness.showDialog | Show test harness dialog box |
Test Sequences
Steps, Transitions, and Symbols
sltest.testsequence.addStep | Add test sequence step |
sltest.testsequence.addStepAfter | Add test sequence step after existing step |
sltest.testsequence.addStepBefore | Add test sequence step before existing step |
sltest.testsequence.addSymbol | Add symbol to test sequence |
sltest.testsequence.addTransition | Add new transition to test sequence step |
sltest.testsequence.deleteStep | Delete test sequence step |
sltest.testsequence.deleteSymbol | Delete test sequence block symbol |
sltest.testsequence.deleteTransition | Delete test sequence transition |
sltest.testsequence.editStep | Edit test sequence step |
sltest.testsequence.editSymbol | Edit symbol in Test Sequence block |
sltest.testsequence.editTransition | Edit test sequence step transition |
sltest.testsequence.find | Find Test Sequence blocks |
sltest.testsequence.findStep | Find test sequence steps |
sltest.testsequence.findSymbol | Find Test Sequence block symbols |
sltest.testsequence.getProperty | Get Test Sequence block properties |
sltest.testsequence.newBlock | Create Test Sequence block |
sltest.testsequence.readStep | Read Test Sequence block steps |
sltest.testsequence.readSymbol | Read Test Sequence block symbol properties |
sltest.testsequence.readTransition | Read properties of test sequence transition |
sltest.testsequence.setProperty | Set Test Sequence block properties |
Scenarios
sltest.testsequence.activateScenario | Set Test Sequence block scenario as active (Since R2020b) |
sltest.testsequence.addScenario | Add new scenario to Test Sequence block (Since R2020b) |
sltest.testsequence.deleteScenario | Delete scenario from Test Sequence block (Since R2020b) |
sltest.testsequence.editScenario | Edit Test Sequence block test scenario properties (Since R2020b) |
sltest.testsequence.getActiveScenario | Get Test Sequence block active scenario (Since R2020b) |
sltest.testsequence.getAllScenarios | Get names of all Test Sequence block scenarios (Since R2020b) |
sltest.testsequence.getScenarioControlSource | Get source that controls Test Sequence active scenario (Since R2020b) |
sltest.testsequence.isUsingScenarios | Determine whether Test Sequence block uses scenarios (Since R2020b) |
sltest.testsequence.setScenarioControlSource | Set source controlling Test Sequence active scenario (Since R2020b) |
sltest.testsequence.useScenario | Convert Test Sequence block to scenario mode (Since R2020b) |
Test Assessments
sltest.Assessment | Access assessment from set |
sltest.AssessmentSet | Access a set of assessments from a simulation |
sltest.getAssessments | Returns test assessment set object |
sltest.testmanager.Assessment | Logical or temporal assessment object (Since R2022a) |
sltest.testmanager.AssessmentSymbol | Symbol used in assessment (Since R2022a) |
Test Execution
sltest.testmanager.run | Run tests with Test Manager |
sltest.testmanager.CoverageSettings | Modify coverage settings |
sltest.plugins.coverage.CoverageMetrics | Specify coverage metrics for tests run with MATLAB Unit Test framework |
sltest.testmanager.addTestsForMissingCoverage | Add tests to increase coverage (Since R2022a) |
sltest.testmanager.mergeCoverage | Merge coverage results from two or more test result sets |
sltest.testmanager.TestOptions | Options for adding test coverage (Since R2022a) |
sltest.xil.framework.Framework | Initialize test bench, start and stop simulation, and display test bench, variable, and task (Since R2022a) |
sltest.xil.framework.FrameworkConfiguration | Configure test bench ports and variable mapping (Since R2022a) |
sltest.xil.framework.TestVariable | Read and write variable mapped to test bench (Since R2022a) |
sltest.xil.framework.Stimulation | Control external input to test bench (Since R2022a) |
sltest.xil.framework.Acquisition | Control signal data logging on test bench and retrieve logged data (Since R2022a) |
sltest.CodeImporter | Import C or C++ code into Simulink for testing (Since R2021a) |
sltest.CodeImporter.SandboxSettings | Sandbox settings for C code testing (Since R2021a) |
Results and Reports
sltest.testmanager.ResultSet | Access result set data |
sltest.testmanager.TestFileResult | Access test file results data |
sltest.testmanager.TestSuiteResult | Access test suite results data |
sltest.testmanager.TestCaseResult | Access test case results data |
sltest.testmanager.TestIterationResult | Access test iteration result data |
sltest.testmanager.ComparisonRunResult | Access result of a comparison test |
sltest.testmanager.ComparisonSignalResult | Access signal comparison results from a baseline or equivalence result |
sltest.testmanager.CustomCriteriaResult | View custom criteria test result |
sltest.testmanager.importResults | Import Test Manager results file |
sltest.testmanager.exportResults | Export results set from Test Manager |
sltest.testmanager.getResultSets | Returns result set objects in Test Manager |
sltest.testmanager.clearResults | Clear results from Test Manager |
sltest.testmanager.TimingInfo | Test execution timing information object (Since R2024a) |
sltest.testmanager.report | Generate report of test results |
sltest.testmanager.TestResultReport | Customize generated results report |
sltest.testmanager.TestSpecReport | Generate report of test specifications |
sltest.testmanager.DiagnosticRecord | View custom criteria diagnostic information |
sltest.testmanager.TestResultContainer | Container for MLDATX test file results from MATLAB Unit Test run
or runInParallel (Since R2022b) |
sltest.testmanager.AssessmentResult | Access logical and temporal assessment results data (Since R2023b) |
sltest.testmanager.AssessmentResultSet | Access logical and temporal assessment result set data (Since R2023b) |
Operations and Preferences
sltest.testmanager.view | Launch the Simulink Test Manager |
sltest.testmanager.setpref | Set Test Manager preferences |
sltest.testmanager.getpref | Get Test Manager preferences |
sltest.testmanager.Options | Return and specify test file options |
sltest.testmanager.find | Find test case in test file (Since R2024a) |
sltest.testmanager.close | Close the Simulink Test Manager |
Topics
- Create and Run Test Cases with Scripts
Examples of how to create and run tests using the programmatic interface.
- Test Models Using MATLAB-Based Simulink Tests
Write test files in MATLAB that can be used in the Test Manager.
- Programmatically Create and Run Test Sequence Scenarios
Add test scenarios to Test Sequence block programmatically.
Featured Examples
Programmatically Create a Test Sequence
Create a test harness and test sequence using the programmatic interface. You create a test harness and a Test Sequence block, and author a test sequence to verify two functional attributes of a cruise control system.
Using MATLAB-Based Simulink Tests in the Test Manager
Use MATLAB-based Simulink test to simulate a model and verify it against a baseline.
Collect Coverage Using MATLAB-Based Simulink Tests
Collect model coverage using test scripts and load to Test Manager using MATLAB Test Framework.
Append Code to a Test Report
Use a customization class to print integrated code in a test results report. If you test models that include handwritten code, you can print the code to a report to be reviewed with the test results.
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)