Create comprehensive MATLAB unit tests using the MATLAB Testing Framework. Use when generating test files, test cases, unit tests, test suites, or when the user requests testing for MATLAB code, functions, or classes.
View on GitHubSelect agents to install to:
npx add-skill https://github.com/matlab/skills/blob/main/skills/matlab-test-generator/SKILL.md -a claude-code --skill matlab-test-generatorInstallation paths:
.claude/skills/matlab-test-generator/# MATLAB Test Generator
This skill provides comprehensive guidelines for creating robust unit tests using the MATLAB Testing Framework. Generate test classes, test methods, and test suites following MATLAB best practices.
## When to Use This Skill
- Creating unit tests for MATLAB functions or classes
- Generating test suites for existing code
- Writing test cases with assertions and fixtures
- Creating parameterized tests
- Setting up test environments with setup/teardown methods
- When user requests testing, test coverage, or mentions unit tests
## MATLAB Testing Framework Overview
MATLAB supports multiple testing approaches:
1. **Script-Based Tests** - Simple test scripts with assertions
2. **Function-Based Tests** - Test functions with local functions for each test
3. **Class-Based Tests** - Full-featured test classes (recommended for complex testing)
## Test Class Structure
### Basic Test Class Template
```matlab
classdef MyFunctionTest < matlab.unittest.TestCase
% Tests for myFunction
properties (TestParameter)
% Define parameters for parameterized tests
end
properties
% Test fixtures and shared data
end
methods (TestClassSetup)
% Runs once before all tests
end
methods (TestClassTeardown)
% Runs once after all tests
end
methods (TestMethodSetup)
% Runs before each test method
end
methods (TestMethodTeardown)
% Runs after each test method
end
methods (Test)
% Individual test methods
end
end
```
## Critical Rules
### File Naming
- **Test files MUST end with `Test.m`** (e.g., `myFunctionTest.m`)
- Class name must match filename
- Follow PascalCase naming convention
- Place in `tests/` directory or alongside source with `Test` suffix
### Test Method Naming
- Use descriptive, readable names
- Start with lowercase letter
- Use camelCase
- Describe what is being tested
- Example: `testAdditionWithPositiveNumbers`
### Assertions
Always