Generates and structures MATLAB unit tests using matlab.unittest and matlab.uitest frameworks. Supports class-based tests, parameterized testing, fixtures, mocking, and App Designer app testing. Use when writing or adding tests, creating test classes, or parameterizing tests.
Ships in matlab-software-development. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Generate, structure, and organize MATLAB unit tests using the matlab.unittest and matlab.uitest frameworks.
matlab-run-testsmatlab-run-testsmatlab-run-testsif, switch, for, or try/catch. Follow Arrange-Act-Assert. If a test needs conditionals, split into separate methodsrun_matlab_test_file or evaluate_matlab_code to run tests after writing. For advanced test execution (coverage, filtering, CI), see the matlab-run-tests skillrun_matlab_test_file MCP tool to confirm tests passrun_matlab_test_file MCP tool to confirm tests pass| 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 |
| Level | On failure | When to use |
|---|---|---|
verify | Continues test | Default — most assertions |
assert | Stops current test | Setup validation |
fatalAssert | Stops entire suite | Environment preconditions |
assume | Skips test | Conditional execution (e.g., toolbox check) |
classdef computeAreaTest < matlab.unittest.TestCase
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
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
Error testing — identical verifyError logic, only inputs and error IDs vary:
properties (TestParameter)
InvalidInput = struct( ...
'zeroDivisor', struct('input', {{5, 0}}, 'errorId', 'fn:zeroDivisor'), ...
'stringArg', struct('input', {{'hello', 1}}, 'errorId', 'fn:nonNumeric'), ...
'cellArg', struct('input', {{{1}, 2}}, 'errorId', 'fn:nonNumeric'))
end
methods (Test)
function testInvalidInputThrows(testCase, InvalidInput)
testCase.verifyError(@() fn(InvalidInput.input{:}), InvalidInput.errorId);
end
end
For advanced parameterization (combinations, dynamic parameters, ClassSetupParameter), see references/parameterized-tests-guidance.md.
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 references/fixtures-guidance.md.
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
Use TestTags for selective execution:
methods (Test, TestTags = {'Unit'})
function testFastCalculation(testCase)
% ...
end
end
methods (Test, TestTags = {'Integration', 'Slow'})
function testFullPipeline(testCase)
% ...
end
end
For testing apps with programmatic UI gestures (press, choose, type, drag), see references/app-testing-guidance.md.
Key points:
matlab.uitest.TestCase (not matlab.unittest.TestCase)drawnow after app creation, before first gestureuilabel.Text with char ('text'), not string ("text").Enable with matlab.lang.OnOffSwitchState.on/.offFor baseline, regression, gold-file, snapshot, or characterization tests, use matlabtest.parameters.matfileBaseline + verifyEqualsBaseline (requires MATLAB Test, R2024b+) instead of hardcoding expected values or manually loading reference data.
TestParameter property per baseline value, using matlabtest.parameters.matfileBaseline with VariableName. Consolidate related baselines into a single MAT file.verifyEqualsBaseline. Pass AbsTol or RelTol for floating-point tolerance.properties (TestParameter)
result = matlabtest.parameters.matfileBaseline( ...
"baselines/output.mat", VariableName="result")
end
methods (Test)
function testOutput(testCase, result)
actual = myFunction(inputData);
testCase.verifyEqualsBaseline(actual, result);
end
end
Never use verifyEqual with hardcoded or manually-computed expected values for baseline/regression/gold-file tests. Always use matfileBaseline + verifyEqualsBaseline — even when tolerance is needed (pass AbsTol/RelTol to verifyEqualsBaseline).
Store baselines in baselines/ relative to the test file. For detailed patterns, multiple-variable consolidation, and baseline generation, see references/baseline-tests-guidance.md.
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 | references/fixtures-guidance.md |
| Floating-point tolerance selection, constraint objects, custom constraints | references/constraints-guidance.md |
| Multiple parameters, dynamic parameters, combination strategies | references/parameterized-tests-guidance.md |
| Code depends on external services, needs mock objects or dependency injection | references/mocking-guidance.md |
| Testing App Designer apps with gestures, dialogs, async callbacks | references/app-testing-guidance.md |
| Baseline/regression tests against stored reference data, golden file tests | references/baseline-tests-guidance.md |
matlab.unittest.TestCase<functionName>Test.m and place in tests/ directoryverify qualifications by default — they let all tests run even if one failsAbsTol for every floating-point comparison — never rely on exact equalityaddTeardown for cleanup — it runs even if the test failsTestParameter for readable parameterized test namesrun_matlab_test_file MCP tool for automatic result captureCopyright 2026 The MathWorks, Inc.
manifest.yaml (opens in a new tab)references/app-testing-guidance.md (opens in a new tab)references/baseline-tests-guidance.md (opens in a new tab)references/constraints-guidance.md (opens in a new tab)references/fixtures-guidance.md (opens in a new tab)references/mocking-guidance.md (opens in a new tab)references/parameterized-tests-guidance.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/matlab-software-development:matlab-write-testsfrom matlab-software-development
npx claudepluginhub matlab/matlab-agentic-toolkit --plugin matlab-software-development11 skills in this plugin
/matlab-configure-toml-projectUse whenever "project" or "matlab.toml" is mentioned in a MATLAB context.
This includes creating, editing, organizing, or configuring MATLAB projects,
declaring MATLAB package dependencies or reference projects, setting up paths,
lifecycle scripts, shortcuts, MATLAB packages, or asking about project structure.
/matlab-instrument-opentelemetry-tracingAdd OpenTelemetry tracing to MATLAB code. Use when the user asks to "add tracing", "instrument with spans", "add OpenTelemetry", "trace my code", "add observability" (when about tracing), or mentions "spans", "distributed tracing", or "OTel tracing" in the context of MATLAB functions. Covers span creation, parent-child context propagation, error handling, attributes, events, and semantic conventions.
/matlab-modernize-codeModernize removed or discouraged MATLAB functions and patterns. Use when the check_matlab_code 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.
Other plugins' skills for the same job