Testing Simulink Models
Requires Simulink Test and R2023a or later. The requirement-driven entry point also requires Requirements Toolbox. The coverage workflow also requires Simulink Coverage. If Simulink Test is unavailable, use simulating-simulink-models with manual assertions.
When to Use
- Writing pass/fail tests for a Simulink model or subsystem
- Verifying expected behavior against requirements or acceptance criteria
- Creating regression tests to catch future breakage
- Reproducing and validating bug fixes with structured assertions
- Collecting decision coverage metrics
- Authoring persistent tests from linked requirements or a behavioral spec
When NOT to Use
- Building or editing model structure → use
building-simulink-models
- Running simulations for data exploration, sweeps, or custom analysis → use
simulating-simulink-models
- Querying or resolving parameter values → use
model_query_params / model_resolve_params
- Creating or editing requirements → use
generate-requirement-drafts
- Injecting faults onto model signals without test authoring → use
inject-faults
- FMEA, FHA, FTA, or other safety analysis documents → use
manage-safety-analysis
- Simulink Test is not installed → fall back to
simulating-simulink-models with manual assertions
Testing Approaches
This skill provides two testing approaches. Choose based on task context:
|
Gherkin (model_test) |
Simulink Test API (test_create family) |
| Persistence |
Ephemeral — harness discarded after session |
Persistent — .mldatx files remain in project |
| Speed |
~3s (draft mode) |
~60s (full Simulink Test infrastructure) |
| Traceability |
None |
Full requirement linking via .slreqx |
| Use case |
Bug fixes, quick validation, agentic loop |
Certification, systematic testing, formal V&V; also takes behavioral specs |
| Approval needed |
No |
Yes — engineer reviews test plan before execution |
| Coverage |
coverage parameter ('none' or 'decision') |
Via test_run options |
| Toolbox |
Simulink Test |
Simulink Test (+ Requirements Toolbox for requirement path) |
→ For Gherkin testing, read references/gherkin-based-fast-testing.md
→ For Simulink Test API authoring (requirements / behavioral spec), read references/simulink-test-authoring.md
Workflow — Gherkin (Quick Validation)
- Understand the component: Use
model_overview and model_read on the target subsystem to identify inputs, outputs, and expected behavior.
- Write the
.feature file: Author a Gherkin test following the syntax in references/gherkin-based-fast-testing.md. Start with one scenario covering the primary nominal case.
- Cap StopTime before running: Check the model's StopTime with
model_query_params. If it is inf (or unset/auto), you MUST pass a finite stop time to model_test — an infinite sim never returns and hangs MATLAB. Pick a finite value that lets the behavior settle (2–30s for a step response).
- Run in draft mode: Call
model_test with draft_mode='true' for rapid iteration (~3s). Fix syntax or signal errors.
- Run full compilation: Once draft passes, re-run with
draft_mode='false' to validate against the actual compiled model (catches type/dimension mismatches).
- Expand coverage: Add scenarios for edge cases, fault conditions, and boundary behavior. Use
coverage='decision' to identify untested branches.
Workflow — Simulink Test API (Persistent)
- Understand the component: Use
model_overview and model_read on the target subsystem to identify inputs, outputs, and expected behavior.
- Propose test plan → wait for approval: Present what to test, at what scope, and why. Do not call
test_create until the engineer approves.
- Create test cases: Call
test_create with the appropriate entry point — component/model only or requirement-driven (RequirementID + ReqSetPath). Pass TestFile as an absolute path under the working folder (never a bare filename — it would land in the skill's scripts/ dir, since that is the project_path). See references/simulink-test-authoring.md for call shapes.
- Propose test configuration → wait for approval: Present stop time, sim config, signal logging, assessments, and parameter overrides for each test case. Do not call
test_edit until the engineer approves. Always set a finite StopTime via test_edit — if the model's StopTime is inf (or unset), the test run never returns and hangs MATLAB. Choose a finite value that lets the behavior settle (2–30s for a step response).
- Run and report: Call
test_run, present pass/fail summary with assessment detail. Engineer decides next steps.
Guardrails
Always
- Inspect model (
model_overview / model_read) before writing tests — otherwise you write tests against wrong I/O
- Report failures with assessment names, conditions, and signal summaries — users can't diagnose without detail
- Never run a sim or test with StopTime=
inf. Check StopTime before any model_test/test_run; if it is inf or unset, override it with a finite value first. An infinite sim never returns and hangs the MATLAB session (and, in a shared session, every subsequent task).
Never
- Guess pass/fail criteria — ask the user if unclear
- Change MATLAB working directory while a model is open — breaks harness cache
References
references/gherkin-based-fast-testing.md — Gherkin syntax, draft mode, coverage, Simscape constraints
references/simulink-test-authoring.md — API manual: setup, constraints, test_create entry shapes, edit/read/run signatures
references/assessment-format.md — LoggedSignals and Assessments struct formats
assets/test-structure-template.md — Test structure proposal template (requirement-driven path)
assets/test-config-template.md — Test configuration proposal template (requirement-driven path)
Copyright 2026 The MathWorks, Inc.
1---2name: testing-simulink-models3description: Tests Simulink models using either ephemeral Gherkin-based tests (model_test) for quick validation or persistent tests (Simulink Test API) authored from requirements or behavioral specs. Requires Simulink Test.4license: https://www.mathworks.com/content/dam/mathworks/license/pmrl/lic5---6
7# Testing Simulink Models
8
9Requires **Simulink Test** and **R2023a or later**. The requirement-driven entry point also requires **Requirements Toolbox**. The coverage workflow also requires **Simulink Coverage**. If Simulink Test is unavailable, use `simulating-simulink-models` with manual assertions.
10
11## When to Use
12
13- Writing pass/fail tests for a Simulink model or subsystem
14- Verifying expected behavior against requirements or acceptance criteria
15- Creating regression tests to catch future breakage
16- Reproducing and validating bug fixes with structured assertions
17- Collecting decision coverage metrics
18- Authoring persistent tests from linked requirements or a behavioral spec
19
20## When NOT to Use
21
22- **Building or editing model structure** → use `building-simulink-models`
23- **Running simulations for data exploration, sweeps, or custom analysis** → use `simulating-simulink-models`
24- **Querying or resolving parameter values** → use `model_query_params` / `model_resolve_params`
25- **Creating or editing requirements** → use `generate-requirement-drafts`
26- **Injecting faults onto model signals without test authoring** → use `inject-faults`
27- **FMEA, FHA, FTA, or other safety analysis documents** → use `manage-safety-analysis`
28- **Simulink Test is not installed** → fall back to `simulating-simulink-models` with manual assertions
29
30## Testing Approaches
31
32This skill provides two testing approaches. Choose based on task context:
33
34| | Gherkin (`model_test`) | Simulink Test API (`test_create` family) |
35|---|---|---|
36| Persistence | Ephemeral — harness discarded after session | Persistent — .mldatx files remain in project |
37| Speed | ~3s (draft mode) | ~60s (full Simulink Test infrastructure) |
38| Traceability | None | Full requirement linking via `.slreqx` |
39| Use case | Bug fixes, quick validation, agentic loop | Certification, systematic testing, formal V&V; also takes behavioral specs |
40| Approval needed | No | Yes — engineer reviews test plan before execution |
41| Coverage | `coverage` parameter (`'none'` or `'decision'`) | Via `test_run` options |
42| Toolbox | Simulink Test | Simulink Test (+ Requirements Toolbox for requirement path) |
43
44→ For Gherkin testing, read `references/gherkin-based-fast-testing.md`
45→ For Simulink Test API authoring (requirements / behavioral spec), read `references/simulink-test-authoring.md`
46
47## Workflow — Gherkin (Quick Validation)
48
491. **Understand the component:** Use `model_overview` and `model_read` on the target subsystem to identify inputs, outputs, and expected behavior.
502. **Write the `.feature` file:** Author a Gherkin test following the syntax in `references/gherkin-based-fast-testing.md`. Start with one scenario covering the primary nominal case.
513. **Cap StopTime before running:** Check the model's StopTime with `model_query_params`. If it is `inf` (or unset/`auto`), you MUST pass a finite stop time to `model_test` — an infinite sim never returns and hangs MATLAB. Pick a finite value that lets the behavior settle (2–30s for a step response).
524. **Run in draft mode:** Call `model_test` with `draft_mode='true'` for rapid iteration (~3s). Fix syntax or signal errors.
535. **Run full compilation:** Once draft passes, re-run with `draft_mode='false'` to validate against the actual compiled model (catches type/dimension mismatches).
546. **Expand coverage:** Add scenarios for edge cases, fault conditions, and boundary behavior. Use `coverage='decision'` to identify untested branches.
55
56## Workflow — Simulink Test API (Persistent)
57
581. **Understand the component:** Use `model_overview` and `model_read` on the target subsystem to identify inputs, outputs, and expected behavior.
592. **Propose test plan → wait for approval:** Present what to test, at what scope, and why. Do not call `test_create` until the engineer approves.
603. **Create test cases:** Call `test_create` with the appropriate entry point — component/model only or requirement-driven (`RequirementID` + `ReqSetPath`). Pass `TestFile` as an **absolute path** under the working folder (never a bare filename — it would land in the skill's `scripts/` dir, since that is the `project_path`). See `references/simulink-test-authoring.md` for call shapes.
614. **Propose test configuration → wait for approval:** Present stop time, sim config, signal logging, assessments, and parameter overrides for each test case. Do not call `test_edit` until the engineer approves. **Always set a finite `StopTime` via `test_edit`** — if the model's StopTime is `inf` (or unset), the test run never returns and hangs MATLAB. Choose a finite value that lets the behavior settle (2–30s for a step response).
625. **Run and report:** Call `test_run`, present pass/fail summary with assessment detail. Engineer decides next steps.
63
64## Guardrails
65
66### Always
67
68- Inspect model (`model_overview` / `model_read`) before writing tests — otherwise you write tests against wrong I/O
69- Report failures with assessment names, conditions, and signal summaries — users can't diagnose without detail
70- **Never run a sim or test with StopTime=`inf`.** Check StopTime before any `model_test`/`test_run`; if it is `inf` or unset, override it with a finite value first. An infinite sim never returns and hangs the MATLAB session (and, in a shared session, every subsequent task).
71
72### Never
73
74- Guess pass/fail criteria — ask the user if unclear
75- Change MATLAB working directory while a model is open — breaks harness cache
76
77## References
78
79- `references/gherkin-based-fast-testing.md` — Gherkin syntax, draft mode, coverage, Simscape constraints
80- `references/simulink-test-authoring.md` — API manual: setup, constraints, test_create entry shapes, edit/read/run signatures
81- `references/assessment-format.md` — LoggedSignals and Assessments struct formats
82- `assets/test-structure-template.md` — Test structure proposal template (requirement-driven path)
83- `assets/test-config-template.md` — Test configuration proposal template (requirement-driven path)
84
85----
86
87Copyright 2026 The MathWorks, Inc.
88
89----