Skip to content

matlab/matlab-agentic-toolkit / skills-catalog/matlab-software-development/matlab-run-tests

matlab-run-tests

Verified

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.

references/test-execution-guidance.md

View on GitHub
# Test Execution and CI/CD

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

## Running Tests

```matlab
results = runtests('tests');                              % all tests in directory
results = runtests('computeAreaTest');                     % specific file
results = runtests('computeAreaTest/testSquare');          % specific method
```

### Filtering Options

```matlab
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

```matlab
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

```matlab
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

```matlab
buildtool              % run default task
buildtool test         % run specific task
```

### CI Pipeline Configurations

#### GitHub Actions

```yaml
# .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

```yaml
# azure-pipelines.yml
trigger: [main]
pool:
  vmImage: 'ubuntu-latest'
steps:
  - task: InstallMATLAB@1
  - task: RunMATLABBuild@1
```

#### GitLab CI

```yaml
# .gitlab-ci.yml
test:
  image: mathworks/matlab:r2024a
  script:
    - matlab -batch "buildtool"
```

----

Copyright 2026 The MathWorks, Inc.

----

finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall