Generated banner for Matlab Run Tests
Generated logo for Matlab Run Tests

Matlab Run Tests

MathWorksOfficialCreated by MathWorks

  • Skill
  • Tool integration
  • Software development
  • BSD-2-Clause
  • No issues found

From the author

Run MATLAB test suites and analyze results, including test filtering, parallel execution, result diagnostics, code coverage collection, gap analysis, and CI/CD with buildtool. Use when running tests, filtering test suites, analyzing test failures, checking, collecting, or analyzing coverage, justifying uncovered code, or configuring CI pipelines. Do NOT use for writing, generating, or structuring tests. Do NOT use for Simulink coverage or Simulink testing workflows.
— the description by MathWorks

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides a structured workflow for running and managing MATLAB test suites. It covers test execution, filtering, parallel processing, and diagnostic reporting. Additionally, it details how to collect and analyze code coverage metrics, including statement, decision, condition, and MC/DC levels, as well as data type and size coverage. It also supports CI/CD integration using MATLAB buildtool.

What it does

  • Executes MATLAB test suites with support for filtering by name, tag, or folder.
  • Provides diagnostic reporting for failed or incomplete test results.
  • Configures code coverage collection using plugins to measure statement, decision, condition, and MC/DC metrics.
  • Extracts and analyzes data type and size coverage for function inputs.
  • Integrates with CI/CD pipelines using buildfile.m and buildtool.
  • Supports parallel test execution to improve performance.

When to use it

  • When you need to run an existing MATLAB test suite.
  • When you need to verify code coverage metrics for your source code.
  • When you are setting up or configuring CI/CD pipelines for MATLAB projects.
  • When you need to diagnose why specific tests are failing or incomplete.
  • When you need to filter large test suites to run only relevant tests.

Advantages

  • Enables programmatic control over test execution and reporting.
  • Provides granular visibility into code coverage and testing gaps.
  • Facilitates automated testing workflows within CI/CD environments.
  • Supports advanced coverage metrics like MC/DC and data type/size analysis.

Usage examples

“Run all tests in the 'tests' folder using parallel execution.”
The agent will execute runtests('tests', UseParallel=true) and report the pass/fail results.
“Collect MC/DC coverage for the 'src' folder.”
The agent will set up a TestRunner with a CodeCoveragePlugin, run the tests, and output the coverage summary.
“Show me which tests failed in my last run.”
The agent will iterate through the results array, identify failed tests, and display their diagnostic records.
“How do I configure a buildfile for my CI pipeline?”
The agent will provide a template for buildfile.m including a TestTask and instructions for CI integration.

Install

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/matlab/matlab-run-tests/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip matlab-run-tests.zip -d .agents/skills

Documentation by MathWorks

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
  1. Run tests — Execute via run_matlab_test_file MCP tool or runtests with filtering

  2. Analyze results — Report pass/fail counts, iterate failed tests for diagnostics

  3. Verify — Confirm all tests pass before proceeding to coverage or CI

Coverage analysis (when requested)
  1. Collect — Set up TestRunner with CodeCoveragePlugin and CoverageResult

  2. Report summary — Call coverageSummary and present percentages to user

  3. Act on results — Generate reports, analyze gaps, or justify — as user directs

CI/CD setup
  1. Create buildfile.m — Define TestTask with source and report options

  2. 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

CategoryFunctionsPurpose
Executionruntests, TestSuite, TestRunnerRun and organize tests
CoverageCodeCoveragePlugin, CoverageResult, coverageSummaryMeasure test coverage
ReportsCoverageReport, generateStandaloneReport, generateCoberturaReportCoverage output formats
CI/CDbuildtool, TestTask, addCodeCoveragePipeline automation
ScriptsprintCoverageGapsPrint 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 detailsreferences/test-execution-guidance.md
Collecting code coverage (MC/DC, statement, decision, condition), analyzing gaps, justifying uncovered code, generated C code coverage, type-size coveragereferences/code-coverage-guidance.md
Creating or modifying filter rule XML for coverage justificationsreferences/justification-filter-rules.md
Extracting data type and size coverage results from hidden propertyreferences/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.


Files

references/justification-filter-rules.md

Justification Filter Rules (XML)

Create a filter rule XML file to justify uncovered coverage outcomes. The file is reusable across runs and can be version-controlled alongside the project.

XML Schema

<?xml version="1.0" encoding="utf-8"?>
<filter>
    <rule type="DECISION" fileName="myFile.m" functionName="myFunction"
          expr="if (x > 0)" index="3" mode="JUSTIFIED"
          rationale="Reason this outcome is unreachable"/>
    <!-- Add more rules as needed -->
</filter>

Attribute Reference

AttributeRequiredDescription
typeYesCoverage metric type. Must be uppercase.
fileNameYesSource file name (not full path, just the filename)
functionNameYesFunction containing the decision
exprYesThe decision/condition expression text as it appears in source
indexYes1-based index of this decision within the function
modeYesAlways "JUSTIFIED"
rationaleYesFree text explaining why this outcome is unreachable

Valid type Values

Justifications can only be applied up to decision level. Condition and MC/DC outcomes cannot be justified.

ValueWhen to use
DECISIONJustifying a decision outcome (true/false branch)

These must be uppercase. Lowercase will not match.

Usage

Supply at collection time

Justifications are applied during the test run — justified outcomes appear as covered in the result:

filterFile = fullfile(projectRoot, "resources", "CodeCoverageFilter.xml");

plugin = CodeCoveragePlugin.forFolder("src", ...
    IncludingSubfolders=true, Producing=format, ...
    Metrics="decision", Filter=filterFile);
Apply after collection

Apply to an existing coverage result:

filteredResult = coverageResult.applyFilter(filterFile);
generateHTMLReport(filteredResult, "coverage-report");
Both forFolder and forFile support Filter
% forFolder
CodeCoveragePlugin.forFolder("src", IncludingSubfolders=true, ...
    Producing=format, Metrics="mcdc", Filter="filters/mcdc_justifications.xml")

% forFile
CodeCoveragePlugin.forFile("src/myAlgorithm.m", ...
    Producing=format, Metrics="decision", Filter="filters/justifications.xml")

Finding the index Value

Count decisions from the top of the function, starting at 1. Every if, elseif, for, while, switch case, and short-circuit operator (&&/||) in a compound expression counts as a decision point.

Use gap analysis output to correlate — the order matches what coverageSummary reports in its description struct.

Complete Workflow Example

% 1. Collect coverage and identify gaps
format = CoverageResult;
plugin = CodeCoveragePlugin.forFolder("src", ...
    IncludingSubfolders=true, Producing=format, Metrics="decision");
runner = TestRunner.withTextOutput;
runner.addPlugin(plugin);
results = runner.run(TestSuite.fromFolder("tests"));
coverageResult = format.Result;

% 2. Analyze gaps
[s, d] = coverageSummary(coverageResult, "decision");
fprintf('Decision coverage: %d/%d (%.1f%%)\n', s(1), s(2), 100*s(1)/s(2));

% 3. Create filter file for structurally unreachable outcomes
filterXml = fullfile(pwd, "resources", "CodeCoverageFilter.xml");
xmlContent = [ ...
    '<?xml version="1.0" encoding="utf-8"?>', newline, ...
    '<filter>', newline, ...
    '    <rule type="DECISION" fileName="shortest_path.m" ', ...
    'functionName="shortest_path" ', ...
    'expr="for iterStep = 1:nodeCnt" index="8" ', ...
    'mode="JUSTIFIED" ', ...
    'rationale="Loop always terminates early via return before all iterations complete"/>', newline, ...
    '    <rule type="DECISION" fileName="shortest_path.m" ', ...
    'functionName="shortest_path" ', ...
    'expr="if (pathLength==realmax)" index="13" ', ...
    'mode="JUSTIFIED" ', ...
    'rationale="If distance were realmax, min==max triggers early return before this check"/>', newline, ...
    '</filter>'];
writelines(string(xmlContent), filterXml);

% 4. Apply and verify
filteredResult = coverageResult.applyFilter(filterXml);
[s2, d2] = coverageSummary(filteredResult, "decision");
fprintf('After justification: %d/%d (%.1f%%)\n', s2(1), s2(2), 100*s2(1)/s2(2));

Best Practices

  • Store filter XML in resources/ folder within the project (version-controllable)

  • Use descriptive rationale — safety auditors will read these

  • One filter file per project is typical; add rules as justifications are confirmed

  • The same filter file can be reused across test runs and CI builds via Filter= parameter

  • Review justifications when source code changes — index values may shift


Copyright 2026 The MathWorks, Inc.


Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Created by
MathWorks
Publisher
MathWorks (Official)
Source
matlab/matlab-agentic-toolkit · skills-catalog/matlab-software-development/matlab-run-tests · commit 2a7f215
Licence
BSD 2-Clause License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE.md)
  • ATTRIBUTION.md (written by AutoGineer)
Synced

AutoGineer is not affiliated with or endorsed by MathWorks.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download matlab-run-tests.zip