Back to Skills

matlab-test-generator

verified

Create comprehensive MATLAB unit tests using the MATLAB Testing Framework. Use when generating test files, test cases, unit tests, test suites, or when the user requests testing for MATLAB code, functions, or classes.

View on GitHub

Marketplace

matlab-skills

matlab/skills

Plugin

matlab-skills

Repository

matlab/skills
22stars

skills/matlab-test-generator/SKILL.md

Last Verified

February 1, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/matlab/skills/blob/main/skills/matlab-test-generator/SKILL.md -a claude-code --skill matlab-test-generator

Installation paths:

Claude
.claude/skills/matlab-test-generator/
Powered by add-skill CLI

Instructions

# MATLAB Test Generator

This skill provides comprehensive guidelines for creating robust unit tests using the MATLAB Testing Framework. Generate test classes, test methods, and test suites following MATLAB best practices.

## When to Use This Skill

- Creating unit tests for MATLAB functions or classes
- Generating test suites for existing code
- Writing test cases with assertions and fixtures
- Creating parameterized tests
- Setting up test environments with setup/teardown methods
- When user requests testing, test coverage, or mentions unit tests

## MATLAB Testing Framework Overview

MATLAB supports multiple testing approaches:

1. **Script-Based Tests** - Simple test scripts with assertions
2. **Function-Based Tests** - Test functions with local functions for each test
3. **Class-Based Tests** - Full-featured test classes (recommended for complex testing)

## Test Class Structure

### Basic Test Class Template

```matlab
classdef MyFunctionTest < matlab.unittest.TestCase
    % Tests for myFunction

    properties (TestParameter)
        % Define parameters for parameterized tests
    end

    properties
        % Test fixtures and shared data
    end

    methods (TestClassSetup)
        % Runs once before all tests
    end

    methods (TestClassTeardown)
        % Runs once after all tests
    end

    methods (TestMethodSetup)
        % Runs before each test method
    end

    methods (TestMethodTeardown)
        % Runs after each test method
    end

    methods (Test)
        % Individual test methods
    end
end
```

## Critical Rules

### File Naming
- **Test files MUST end with `Test.m`** (e.g., `myFunctionTest.m`)
- Class name must match filename
- Follow PascalCase naming convention
- Place in `tests/` directory or alongside source with `Test` suffix

### Test Method Naming
- Use descriptive, readable names
- Start with lowercase letter
- Use camelCase
- Describe what is being tested
- Example: `testAdditionWithPositiveNumbers`

### Assertions
Always

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
10580 chars