matlab-write-test

Generate and run MATLAB unit tests using matlab.unittest and matlab.uitest frameworks.

995|122|Updated Apr 3, 2026
One-click install
npx skills add https://github.com/matlab/matlab-agentic-toolkit --skill matlab-write-test
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: matlab-write-test
Source: https://github.com/matlab/matlab-agentic-toolkit/tree/main/skills-catalog/matlab-core/matlab-write-test
Command: npx skills add https://github.com/matlab/matlab-agentic-toolkit --skill matlab-write-test

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Writing correct, maintainable MATLAB tests requires deep knowledge of the matlab.unittest framework, and AI agents often produce script-based tests, miss edge cases, or use incorrect assertion patterns. This Skill provides the conventions, patterns, and execution workflow to generate class-based tests, run them via MCP tools, and measure coverage.

Core Features & Use Cases

  • Class-Based Test Generation: Creates test classes inheriting from matlab.unittest.TestCase with parameterized tests, fixtures, tags, and Arrange-Act-Assert structure.
  • Coverage and CI/CD: Runs tests with CodeCoveragePlugin, identifies coverage gaps, and configures buildtool pipelines for GitHub Actions, Azure DevOps, and GitLab CI.
  • App Designer Testing: Tests apps programmatically with matlab.uitest gestures like press, choose, type, and drag, including dialog handling and async callbacks.
  • Use Case: Ask the agent to write tests for a computeArea function, and it proposes a test plan, generates a parameterized test class with floating-point tolerances, runs it via the run_matlab_test_file MCP tool, and reports coverage gaps.

Quick Start

Ask the agent to write and run unit tests for your MATLAB function using the matlab-write-test skill.

Frequently Asked Questions about matlab-write-test

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write unit tests in MATLAB with matlab.unittest?

Create a class-based test file inheriting from matlab.unittest.TestCase with test methods inside a methods (Test) block. Use verifyEqual, verifyTrue, and verifyError for assertions, and run tests with runtests or the run_matlab_test_file MCP tool.

How to test MATLAB App Designer apps programmatically?

Inherit your test class from matlab.uitest.TestCase and use gestures like press, choose, type, and drag to simulate user interactions. Call drawnow after app creation, and compare label text with char values and Enable states with matlab.lang.OnOffSwitchState.

How do I measure code coverage for MATLAB tests?

Create a TestRunner, add a CodeCoveragePlugin for your source folder producing CoverageResult and CoverageReport formats, then run the test suite. The CoverageResult object shows statement, function, and decision coverage per file.

Can MATLAB tests run in CI/CD pipelines like GitHub Actions?

Yes, use buildtool with a buildfile.m defining TestTask with source files and report formats. GitHub Actions uses matlab-actions/setup-matlab and run-build, while Azure DevOps and GitLab CI have equivalent MATLAB task integrations.

When should I use parameterized tests in MATLAB?

Use TestParameter properties only when assertion logic is identical across cases and only the data varies. Choose exhaustive, sequential, or pairwise combination modes, and use structs for readable test names in results.

Why do MATLAB app tests fail on Enable or Text comparisons?

UI component properties return specific types: uilabel.Text returns char, and Enable returns matlab.lang.OnOffSwitchState. Compare Text with 'text' char values and Enable with matlab.lang.OnOffSwitchState.on or .off instead of strings.