
matlab-testing
Generate and run MATLAB unit tests using matlab.unittest and matlab.uitest. Parameterized tests, fixtures, mocking, coverage analysis, CI/CD with buildtool, app testing with gestures. Use when creating tests, writing test classes, running test suites, checking coverage, testing apps, or validating MATLAB code.
- Installs
- 76
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/matlab/matlab-agentic-toolkit --skill matlab-testing- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads matlab-testing automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Testing
Generate, structure, and run MATLAB unit tests using the matlab.unittest framework. Covers class-based tests, parameterized testing, fixtures, mocking, coverage analysis, CI/CD integration, and app testing via MCP.
When to Use
- User asks to write tests for a MATLAB function or class
- User wants to run an existing test suite
- User needs coverage analysis or CI/CD configuration
- Test-driven development — writing tests before implementation
- Testing App Designer apps with programmatic gestures (see reference/app-testing-guidance.md)
When NOT to Use
- Testing Simulink models — use Simulink test skills
- Performance benchmarking — use profiling workflows
Must-Follow Rules
- Present a test plan first — For non-trivial test suites, propose test methods and edge cases for user approval before writing code
- Always use class-based tests — Every test file must inherit from
matlab.unittest.TestCase. Never use script-based tests - No logic in test methods — No
if,switch,for, ortry/catch. Follow Arrange-Act-Assert. If a test needs conditionals, split into separate methods - Test public interfaces, not implementation — Never test private methods directly
- Execute via MCP — Use
run_matlab_test_fileorevaluate_matlab_codeto run tests
Workflow
Simple tests (clear behavior, limited scope)
- Briefly state what you'll test (methods + key edge cases)
- Write the test file after user confirms
Standard tests (large codebase, multiple files)
- Gather requirements — Code to test, expected behaviors, error conditions, scope, dependencies
- Present test plan — List test methods, edge cases, parameterization strategy for approval
- Implement — Write tests following the patterns below
- Run — Execute via
run_matlab_test_fileMCP tool - Check coverage — Identify untested paths, add tests
Key Functions
| Category | Functions | Purpose |
|---|---|---|
| Equality | verifyEqual, verifyNotEqual | Compare values (use AbsTol for floats) |
| Boolean | verifyTrue, verifyFalse | Check logical conditions |
| Size/type | verifySize, verifyClass, verifyEmpty | Structural checks |
| Errors | verifyError | Confirm error is thrown with correct ID |
| Warnings | verifyWarning, verifyWarningFree | Check warning behavior |
| Infra | runtests, TestSuite, TestRunner | Run and organize tests |
| Coverage | CodeCoveragePlugin, CoverageResult | Measure test coverage |
Qualification Levels
| Level | On failure | When to use |
|---|---|---|
verify | Continues test | Default — most assertions |
assert | Stops current test | Setup validation |
fatal | Stops entire suite | Environment preconditions |
assume | Skips test | Conditional execution (e.g., toolbox check) |
Patterns
Basic Test Class
classdef computeAreaTest < matlab.unittest.TestCase
%computeAreaTest Tests for the computeArea function.
methods (Test)
function testSquare(testCase)
result = computeArea(5, 5);
testCase.verifyEqual(result, 25);
end
function testFloatingPoint(testCase)
result = computeArea(1/3, 3);
testCase.verifyEqual(result, 1, AbsTol=1e-12);
end
function testNegativeInputErrors(testCase)
testCase.verifyError( ...
@() computeArea(-1, 5), 'computeArea:negativeInput');
end
end
end
Parameterized Tests
Parameterize only when assertion logic is identical across all cases — only the data varies. Use struct for readable test names:
classdef unitConverterTest < matlab.unittest.TestCase
properties (TestParameter)
conversionCase = struct( ...
'freezing', struct('input', 0, 'expected', 32), ...
'boiling', struct('input', 100, 'expected', 212), ...
'bodyTemp', struct('input', 37, 'expected', 98.6));
end
methods (Test)
function testCelsiusToFahrenheit(testCase, conversionCase)
result = celsiusToFahrenheit(conversionCase.input);
testCase.verifyEqual(result, conversionCase.expected, AbsTol=1e-10);
end
end
end
For advanced parameterization (combinations, dynamic parameters, ClassSetupParameter), see reference/parameterized-tests-guidance.md.
Setup, Teardown, and Fixtures
Prefer addTeardown over TestMethodTeardown blocks. Use PathFixture to add source folders:
classdef fileProcessorTest < matlab.unittest.TestCase
methods (TestClassSetup)
function addSourceToPath(testCase)
srcFolder = fullfile(fileparts(fileparts(mfilename('fullpath'))), 'src');
testCase.applyFixture(matlab.unittest.fixtures.PathFixture(srcFolder, ...
IncludingSubfolders=true));
end
end
methods (Test)
function testProcessFile(testCase)
tmpDir = string(tempname);
mkdir(tmpDir);
testCase.addTeardown(@() rmdir(tmpDir, 's'));
testFile = fullfile(tmpDir, "data.csv");
writematrix(rand(10, 3), testFile);
result = processFile(testFile);
testCase.verifySize(result, [10 3]);
end
end
end
For built-in fixtures, custom fixtures, and shared fixtures, see reference/fixtures-guidance.md.
Determinism
Seed the RNG and restore it in teardown for reproducible tests:
methods (TestMethodSetup)
function resetRandomSeed(testCase)
originalRng = rng;
testCase.addTeardown(@() rng(originalRng));
rng(42, "twister");
end
end
Test Tags
Use TestTags for selective execution:
methods (Test, TestTags = {'Unit'})
function testFastCalculation(testCase)
% ...
end
end
methods (Test, TestTags = {'Integration', 'Slow'})
function testFullPipeline(testCase)
% ...
end
end
Run by tag: runtests('tests', Tag='Unit') or runtests('tests', ExcludeTag='Slow').
Running Tests
Via MCP
Use the run_matlab_test_file MCP tool for test files. For inline runs with filtering:
results = runtests('tests'); % all tests in folder
results = runtests('tests', Tag='Unit'); % by tag
results = runtests('tests', Name='*Calculator*'); % by name pattern
results = runtests('tests', UseParallel=true); % parallel execution
results = runtests('tests', Strict=true); % warnings = failures
Analyzing Results
disp(results);
for r = results([results.Failed])
fprintf('\nFAILED: %s\n', r.Name);
disp(r.Details.DiagnosticRecord.Report);
end
Coverage Analysis
import matlab.unittest.TestRunner
import matlab.unittest.plugins.CodeCoveragePlugin
import matlab.unittest.plugins.codecoverage.CoverageResult
import matlab.unittest.plugins.codecoverage.CoverageReport
runner = TestRunner.withTextOutput;
covFormat = CoverageResult;
runner.addPlugin(CodeCoveragePlugin.forFolder('src', ...
Producing=[covFormat, CoverageReport('coverage-report')]));
results = runner.run(testsuite('tests'));
covResults = covFormat.Result;
disp(covResults);
For coverage gap analysis, use the printCoverageGaps script in reference/test-execution-guidance.md.
CI/CD Integration
Use buildtool with a buildfile.m for CI pipelines. See reference/test-execution-guidance.md for buildfile.m templates and CI configs (GitHub Actions, Azure DevOps, GitLab CI).
App Designer Testing
For testing apps with programmatic UI gestures (press, choose, type, drag), see reference/app-testing-guidance.md.
Key points:
- Inherit from
matlab.uitest.TestCase(notmatlab.unittest.TestCase) - Call
drawnowafter app creation, before first gesture - Compare
uilabel.Textwith char ('text'), not string ("text") - Compare
.Enablewithmatlab.lang.OnOffSwitchState.on/.off
References
Load these on demand — most tests only need what's in this file.
| Load when... | Reference |
|---|---|
| Tests need setup/teardown, temp dirs, path management, shared state | reference/fixtures-guidance.md |
| Floating-point tolerance selection, constraint objects, custom constraints | reference/constraints-guidance.md |
| Multiple parameters, dynamic parameters, combination strategies | reference/parameterized-tests-guidance.md |
| Code depends on external services, needs mock objects or dependency injection | reference/mocking-guidance.md |
| Running tests in CI, buildtool config, coverage gap analysis | reference/test-execution-guidance.md |
| Testing App Designer apps with gestures, dialogs, async callbacks | reference/app-testing-guidance.md |
Conventions
- Always use class-based tests inheriting from
matlab.unittest.TestCase - Name test files
<functionName>Test.mand place intests/directory - Use
verifyqualifications by default — they let all tests run even if one fails - Use
AbsTolfor every floating-point comparison — never rely on exact equality - No logic in test methods — follow Arrange-Act-Assert
- Use
addTeardownfor cleanup — it runs even if the test fails - Use struct-based
TestParameterfor readable parameterized test names - Keep test methods focused — test one behavior per method
- Tests must be independent and compatible with parallel execution
- Run tests via the
run_matlab_test_fileMCP tool for automatic result capture
Copyright 2026 The MathWorks, Inc.
FAQ
What does the matlab-testing skill do?
Generate and run MATLAB unit tests using matlab.unittest and matlab.uitest. Parameterized tests, fixtures, mocking, coverage analysis, CI/CD with buildtool, app testing with gestures. Use when creating tests, writing test classes, running test suites, checking coverage, testing apps, or validating MATLAB code.
How do I install matlab-testing?
Run npx skills add https://github.com/matlab/matlab-agentic-toolkit --skill matlab-testing in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/matlab-testing/ (personal) or .claude/skills/matlab-testing/ (project).
Which AI agents can use matlab-testing?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is matlab-testing safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains matlab-testing?
It is published by matlab in matlab/matlab-agentic-toolkit. It has 76 recorded installs.
More from matlab/matlab-agentic-toolkit
matlab-review-code
matlab/matlab-agentic-toolkit
Review MATLAB code for quality, performance, maintainability, and adherence to MathWorks coding standards. Uses checkmatlabcode and matlabcodingguidelines. Use when reviewing code, checking style, finding code smells, assessing quality, or preparing code for handoff or publication.
matlab-analyze-data
matlab/matlab-agentic-toolkit
Analyze data using MATLAB. Use when the task involves tables, timetables, time-series data, numeric arrays, sensor matrices, or gridded data — including but not limited to exploring, row filtering, sorting, cleaning, transforming, aggregating, smoothing, padding, trimming, and answering questions about data. MATLAB provides extensive, easy-to-use built-in functions for these workflows with no additional products required.
matlab-design-digital-filter
matlab/matlab-agentic-toolkit
Design and validate digital filters in MATLAB. Use when cleaning up noisy signals, removing interference, filtering signals, designing FIR/IIR filters (lowpass/highpass/bandpass/bandstop/notch), or comparing filters in Filter Analyzer.
matlab-modernize-code
matlab/matlab-agentic-toolkit
Modernize removed or discouraged MATLAB functions and patterns. Use when the checkmatlabcode MCP tool reports that a function "is not recommended", "will be removed in a future release", or "has been removed" — at any severity (info, warning, or error) — when migrating legacy code, or when replacing removed or discouraged APIs with current equivalents. Also applies to discouraged patterns Code Analyzer does not flag (containers.Map, bsxfun, str2num, eval, clear all) and to removed or discouraged functions such as trainNetwork, csvread, xlsread, datenum, guide, svmtrain, ltln2val, webmap.
matlab-create-live-script
matlab/matlab-agentic-toolkit
Create, edit, and run plain-text MATLAB live scripts (.m files) with rich text formatting, LaTeX equations, section breaks, and inline figures. Use when generating tutorials, analysis notebooks, reports, documentation, or educational content, when modifying existing live scripts, or when converting existing binary .mlx files to .m for version control. Requires R2025a+.
matlab-agentic-toolkit-setup
matlab/matlab-agentic-toolkit
Install and configure the MATLAB Agentic Toolkit — detect MATLAB, install the MCP server, register with your AI coding agent, and verify the environment. Supports Claude Code, Codex, GitHub Copilot, Amp, and Gemini CLI.
Popular testing & qa skills
tdd
mattpocock/skills
Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.
grilling
mattpocock/skills
Grill the user relentlessly about a plan, decision, or idea. Use when the user wants to stress-test their thinking, or uses any 'grill' trigger phrases.
migrate-to-shoehorn
mattpocock/skills
Migrate test files from as type assertions to @total-typescript/shoehorn. Use when user mentions shoehorn, wants to replace as in tests, or needs partial test data.
run-train
lllllllama/rigorpilot-skills
Rigor Train skill for deep learning research repositories. Use when a documented or selected training command should be run conservatively for startup verification, short-run verification, full kickoff, or resume, with command, config, seed, log, checkpoint, status, and metric evidence written to standardized trainoutputs/. Do not use for environment setup, exploratory sweeps, speculative idea implementation, or end-to-end orchestration.
test-driven-development
obra/superpowers
Use when implementing any feature or bugfix, before writing implementation code
finishing-a-development-branch
obra/superpowers
Use when implementation is complete, all tests pass, and you need to decide how to integrate the work