matlab/matlab-agentic-toolkit / skills-catalog/matlab-software-development/matlab-write-tests
matlab-write-tests
VerifiedGenerate and structure MATLAB unit tests using matlab.unittest and matlab.uitest features, including class-based tests, parameterized testing, fixtures, mocking, and app testing with gestures. Use when writing, generating, or adding tests, creating test classes, adding test methods, parameterizing tests, setting up fixtures, mocking dependencies, or testing App Designer apps. Do NOT use for running tests, collecting coverage, or CI/CD configuration.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 11.2 KB |
| manifest.yaml | config | 495 B |
| references/app-testing-guidance.md | markdown | 7.3 KB |
| references/baseline-tests-guidance.md | markdown | 6.0 KB |
| references/constraints-guidance.md | markdown | 2.2 KB |
| references/fixtures-guidance.md | markdown | 2.7 KB |
| references/mocking-guidance.md | markdown | 3.3 KB |
| references/parameterized-tests-guidance.md | markdown | 3.6 KB |
references/constraints-guidance.md
View on GitHub# Constraints and Assertions
Advanced verification techniques, tolerances, and custom constraints. For basic assertion usage (`verify*`/`assert*`, `verifyError`, `AbsTol`/`RelTol` syntax), see SKILL.md.
## Floating-Point Comparisons
`AbsTol` and `RelTol` are only supported on `*Equal` methods.
### Choosing Tolerances
| Scenario | Recommended |
|----------|-------------|
| Small values near zero | `AbsTol` only |
| Large values | `RelTol` only |
| Mixed magnitudes | Both |
| Single precision | `AbsTol=1e-6`, `RelTol=1e-5` |
| Double precision | `AbsTol=1e-14`, `RelTol=1e-12` |
## Diagnostic Messages
Add diagnostics that describe what the assertion is checking — they should be meaningful regardless of whether the test passes or fails:
```matlab
testCase.verifyEqual(result, [1 2 3 4 5], ...
"Output must be in ascending order.")
```
## Constraint Objects
Prefer informal APIs (`verifyEqual`, `verifyGreaterThan`, `verifySubstring`, etc.) over `verifyThat` with constraint objects. Only use `verifyThat` when no informal API exists.
### Informal API Mapping
Most constraints map directly to informal equivalents. Non-obvious mappings:
| Constraint class | Informal equivalent |
|---|---|
| `HasElementCount` | `verifyNumElements` |
| `ContainsSubstring` | `verifySubstring` |
| `MatchesRegexp` | `verifyMatches` |
| `Throws` | `verifyError` |
| `IssuesWarnings` | `verifyWarning` |
| `IssuesNoWarnings` | `verifyWarningFree` |
### When to Use `verifyThat`
No informal equivalent exists for these:
- `StartsWithSubstring`, `EndsWithSubstring`
- `IsFinite`, `IsReal`, `IsSameSetAs`
- `EveryElementOf(...)`, `AnyElementOf(...)`
- Boolean combinations (`&`, `|`, `~`)
```matlab
import matlab.unittest.constraints.*
testCase.verifyThat(value, IsEmpty | IsEqualTo(0));
testCase.verifyThat(x, IsGreaterThan(0) & IsLessThan(10));
testCase.verifyThat(array, EveryElementOf(IsGreaterThan(0)));
```
## Custom Constraints
Extend `matlab.unittest.constraints.Constraint` for domain-specific checks. Implement `satisfiedBy(~, actual)` (returns logical) and `getDiagnosticFor(constraint, actual)` (returns `StringDiagnostic`). Use via `testCase.verifyThat(value, MyConstraint)`.
----
Copyright 2026 The MathWorks, Inc.
----
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |