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://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/test-execution-guidance.md

Test Execution and CI/CD

Running tests, analyzing results, and configuring CI/CD pipelines.

Running Tests

results = runtests('tests');                              % all tests in directory
results = runtests('computeAreaTest');                     % specific file
results = runtests('computeAreaTest/testSquare');          % specific method
Filtering Options
results = runtests('tests', Name='*Calculator*');         % by name pattern
results = runtests('tests', Tag='Unit');                  % by tag
results = runtests('tests', ExcludeTag='Slow');           % exclude tag
results = runtests('tests', ProcedureName='testX');       % by procedure
results = runtests('tests', UseParallel=true);            % parallel execution
results = runtests('tests', Strict=true);                 % warnings = failures
results = runtests('tests', Debug=true);                  % debugger on failure
results = runtests('tests', OutputDetail='Detailed');     % verbose output

Parallel requirements: Tests must be independent — no shared state, no order dependence, no shared file system artifacts.

Analyzing Results
results = runtests('tests');
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

CI/CD Integration with buildtool

Always use buildtool with a buildfile.m for CI.

Example buildfile.m
function plan = buildfile
    plan = buildplan(localfunctions);

    plan("clean") = matlab.buildtool.tasks.CleanTask;

    plan("check") = matlab.buildtool.tasks.CodeIssuesTask("src");

    plan("test") = matlab.buildtool.tasks.TestTask("tests", ...
        SourceFiles="src", ...
        ReportFormat=["html", "cobertura"], ...
        OutputDirectory="reports");

    plan("ci") = matlab.buildtool.Task( ...
        Description="Full CI pipeline", ...
        Dependencies=["check", "test"]);

    plan.DefaultTasks = "test";
end
Running buildtool
buildtool              % run default task
buildtool test         % run specific task
CI Pipeline Configurations
GitHub Actions
# .github/workflows/matlab.yml
name: MATLAB Tests
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: matlab-actions/setup-matlab@v2
      - uses: matlab-actions/run-build@v2
Azure DevOps
# azure-pipelines.yml
trigger: [main]
pool:
  vmImage: 'ubuntu-latest'
steps:
  - task: InstallMATLAB@1
  - task: RunMATLABBuild@1
GitLab CI
# .gitlab-ci.yml
test:
  image: mathworks/matlab:r2024a
  script:
    - matlab -batch "buildtool"

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 or MathWorks.

Download ZIP

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