Run Tests
Run MATLAB test suites, analyze results, collect code coverage metrics, and configure CI/CD pipelines using matlab.unittest infrastructure.
When to Use
- User wants to run an existing test suite
- User needs to filter tests by name, tag, or folder
- User wants to analyze test failures or incomplete results
- User needs code coverage collection or analysis
- User wants CI/CD pipeline configuration with buildtool
- User asks about parallel test execution
When NOT to Use
- Writing tests, creating test classes, parameterization, fixtures, mocking — use
matlab-write-tests
- Baseline/regression tests against stored reference data — use
matlab-write-tests
- Testing Simulink models — use Simulink test skills
- Performance benchmarking — use profiling workflows
Workflow
Run and report
- Run tests — Execute via
run_matlab_test_file MCP tool or runtests with filtering
- Analyze results — Report pass/fail counts, iterate failed tests for diagnostics
- Verify — Confirm all tests pass before proceeding to coverage or CI
Coverage analysis (when requested)
- Collect — Set up
TestRunner with CodeCoveragePlugin and CoverageResult
- Report summary — Call
coverageSummary and present percentages to user
- Act on results — Generate reports, analyze gaps, or justify — as user directs
CI/CD setup
- Create buildfile.m — Define
TestTask with source and report options
- Add CI config — GitHub Actions, Azure DevOps, or GitLab CI template
Running Tests
Via MCP
Use the run_matlab_test_file MCP tool to run test files directly. When you need filtering, parallel execution, or other options, use evaluate_matlab_code with runtests:
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
for r = results([results.Incomplete])
fprintf('\nINCOMPLETE: %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
runner = TestRunner.withTextOutput;
covFormat = CoverageResult;
runner.addPlugin(CodeCoveragePlugin.forFolder('src', ...
IncludingSubfolders=true, Producing=covFormat, MetricLevel='mcdc'));
results = runner.run(testsuite('tests'));
covResults = covFormat.Result;
summary = coverageSummary(covResults, "mcdc");
fprintf('Coverage: %d/%d (%.1f%%)\n', sum(summary(:,1)), sum(summary(:,2)), ...
100*sum(summary(:,1))/sum(summary(:,2)));
For detailed coverage workflows — gap analysis, justifications, generated C code coverage, and data type/size coverage — see references/code-coverage-guidance.md.
Key Functions
| Category |
Functions |
Purpose |
| Execution |
runtests, TestSuite, TestRunner |
Run and organize tests |
| Coverage |
CodeCoveragePlugin, CoverageResult, coverageSummary |
Measure test coverage |
| Reports |
CoverageReport, generateStandaloneReport, generateCoberturaReport |
Coverage output formats |
| CI/CD |
buildtool, TestTask, addCodeCoverage |
Pipeline automation |
| Scripts |
printCoverageGaps |
Print all uncovered items across metric levels — see references/code-coverage-guidance.md for interface |
CI/CD Integration
Use buildtool with a buildfile.m for CI pipelines. See references/test-execution-guidance.md for buildfile.m templates and CI configs (GitHub Actions, Azure DevOps, GitLab CI).
For toolbox projects, matlab-package-toolbox generates a buildfile.m in which the packaging task depends on the test task.
References
Load these on demand — most test runs only need what's in this file.
| Load when... |
Reference |
| Running tests in CI, buildtool config, filtering options, parallel execution details |
references/test-execution-guidance.md |
| Collecting code coverage (MC/DC, statement, decision, condition), analyzing gaps, justifying uncovered code, generated C code coverage, type-size coverage |
references/code-coverage-guidance.md |
| Creating or modifying filter rule XML for coverage justifications |
references/justification-filter-rules.md |
| Extracting data type and size coverage results from hidden property |
references/datatype-size-extraction.md |
Conventions
- Always: run tests via the
run_matlab_test_file MCP tool when possible
- Always: report pass/fail summary before taking further action
- Always: check for Failed/Incomplete tests before analyzing coverage
- Prefer:
forFolder with IncludingSubfolders=true as the default source specification for coverage
- Prefer: MC/DC as the default metric level because each level includes all lower levels
- Never: generate coverage reports (HTML, Cobertura) unless the user explicitly requests them
- Never: use
CoverageResult as the only format — always use it as the primary programmatic format
Copyright 2026 The MathWorks, Inc.
1---2name: matlab-run-tests3description: >4 Run MATLAB test suites and analyze results, including test filtering, parallel execution,5 result diagnostics, code coverage collection, gap analysis, and CI/CD with buildtool. Use6 when running tests, filtering test suites, analyzing test failures, checking, collecting,7 or analyzing coverage, justifying uncovered code, or configuring CI pipelines. Do NOT use8 for writing, generating, or structuring tests. Do NOT use for Simulink coverage or9 Simulink testing workflows.10license: https://www.mathworks.com/content/dam/mathworks/license/pmrl/license.md11metadata:12 source: https://skillmd.com/skills/matlab/matlab-run-tests13 author: MathWorks14 version: "1.1"15---1617# Run Tests1819Run MATLAB test suites, analyze results, collect code coverage metrics, and configure CI/CD pipelines using `matlab.unittest` infrastructure.2021## When to Use2223- User wants to run an existing test suite24- User needs to filter tests by name, tag, or folder25- User wants to analyze test failures or incomplete results26- User needs code coverage collection or analysis27- User wants CI/CD pipeline configuration with buildtool28- User asks about parallel test execution2930## When NOT to Use3132- Writing tests, creating test classes, parameterization, fixtures, mocking — use `matlab-write-tests`33- Baseline/regression tests against stored reference data — use `matlab-write-tests`34- Testing Simulink models — use Simulink test skills35- Performance benchmarking — use profiling workflows3637## Workflow3839### Run and report401. **Run tests** — Execute via `run_matlab_test_file` MCP tool or `runtests` with filtering412. **Analyze results** — Report pass/fail counts, iterate failed tests for diagnostics423. **Verify** — Confirm all tests pass before proceeding to coverage or CI4344### Coverage analysis (when requested)451. **Collect** — Set up `TestRunner` with `CodeCoveragePlugin` and `CoverageResult`462. **Report summary** — Call `coverageSummary` and present percentages to user473. **Act on results** — Generate reports, analyze gaps, or justify — as user directs4849### CI/CD setup501. **Create buildfile.m** — Define `TestTask` with source and report options512. **Add CI config** — GitHub Actions, Azure DevOps, or GitLab CI template5253## Running Tests5455### Via MCP5657Use the `run_matlab_test_file` MCP tool to run test files directly. When you need filtering, parallel execution, or other options, use `evaluate_matlab_code` with `runtests`:5859```matlab60results = runtests('tests'); % all tests in folder61results = runtests('tests', Tag='Unit'); % by tag62results = runtests('tests', Name='*Calculator*'); % by name pattern63results = runtests('tests', UseParallel=true); % parallel execution64results = runtests('tests', Strict=true); % warnings = failures65```6667### Analyzing Results6869```matlab70disp(results);7172for r = results([results.Failed])73 fprintf('\nFAILED: %s\n', r.Name);74 disp(r.Details.DiagnosticRecord.Report);75end7677for r = results([results.Incomplete])78 fprintf('\nINCOMPLETE: %s\n', r.Name);79 disp(r.Details.DiagnosticRecord.Report);80end81```8283## Coverage Analysis8485```matlab86import matlab.unittest.TestRunner87import matlab.unittest.plugins.CodeCoveragePlugin88import matlab.unittest.plugins.codecoverage.CoverageResult8990runner = TestRunner.withTextOutput;91covFormat = CoverageResult;92runner.addPlugin(CodeCoveragePlugin.forFolder('src', ...93 IncludingSubfolders=true, Producing=covFormat, MetricLevel='mcdc'));94results = runner.run(testsuite('tests'));9596covResults = covFormat.Result;97summary = coverageSummary(covResults, "mcdc");98fprintf('Coverage: %d/%d (%.1f%%)\n', sum(summary(:,1)), sum(summary(:,2)), ...99 100*sum(summary(:,1))/sum(summary(:,2)));100```101102For detailed coverage workflows — gap analysis, justifications, generated C code coverage, and data type/size coverage — see [references/code-coverage-guidance.md](references/code-coverage-guidance.md).103104## Key Functions105106| Category | Functions | Purpose |107|----------|-----------|---------|108| Execution | `runtests`, `TestSuite`, `TestRunner` | Run and organize tests |109| Coverage | `CodeCoveragePlugin`, `CoverageResult`, `coverageSummary` | Measure test coverage |110| Reports | `CoverageReport`, `generateStandaloneReport`, `generateCoberturaReport` | Coverage output formats |111| CI/CD | `buildtool`, `TestTask`, `addCodeCoverage` | Pipeline automation |112| Scripts | [`printCoverageGaps`](scripts/printCoverageGaps.m) | Print all uncovered items across metric levels — see [references/code-coverage-guidance.md](references/code-coverage-guidance.md) for interface |113114## CI/CD Integration115116Use `buildtool` with a `buildfile.m` for CI pipelines. See [references/test-execution-guidance.md](references/test-execution-guidance.md) for `buildfile.m` templates and CI configs (GitHub Actions, Azure DevOps, GitLab CI).117118For toolbox projects, `matlab-package-toolbox` generates a `buildfile.m` in which the packaging task depends on the test task.119120## References121122Load these on demand — most test runs only need what's in this file.123124| Load when... | Reference |125|---|---|126| Running tests in CI, buildtool config, filtering options, parallel execution details | [references/test-execution-guidance.md](references/test-execution-guidance.md) |127| Collecting code coverage (MC/DC, statement, decision, condition), analyzing gaps, justifying uncovered code, generated C code coverage, type-size coverage | [references/code-coverage-guidance.md](references/code-coverage-guidance.md) |128| Creating or modifying filter rule XML for coverage justifications | [references/justification-filter-rules.md](references/justification-filter-rules.md) |129| Extracting data type and size coverage results from hidden property | [references/datatype-size-extraction.md](references/datatype-size-extraction.md) |130131## Conventions132133- Always: run tests via the `run_matlab_test_file` MCP tool when possible134- Always: report pass/fail summary before taking further action135- Always: check for Failed/Incomplete tests before analyzing coverage136- Prefer: `forFolder` with `IncludingSubfolders=true` as the default source specification for coverage137- Prefer: MC/DC as the default metric level because each level includes all lower levels138- Never: generate coverage reports (HTML, Cobertura) unless the user explicitly requests them139- Never: use `CoverageResult` as the only format — always use it as the primary programmatic format140141----142143Copyright 2026 The MathWorks, Inc.144145----