Main Content

MATLAB Test Manager

Manage MATLAB tests and results for projects

Since R2023a

Description

Use the MATLAB Test Manager to manage tests and test results for projects. You can create and run tests and test suites, view results and failure diagnostics, collect coverage, and view coverage reports. You can also view and verify linked requirements.

To add tests to the test manager:

  1. Add a test file to the project. For more information, see Manage Project Files.

  2. Add a Test label to the file. For more information, see Add Labels to Project Files.

  3. Add tests to the test file. For more information, see Ways to Write Unit Tests.

MATLAB Test Manager with 14 passed tests and 1 failed test.

Open the MATLAB Test Manager App

Open a project, then use one of these approaches to open the app:

  • MATLAB® Toolstrip: In the Project tab, in the Tools menu, under Apps, click MATLAB Test Manager.

  • MATLAB command prompt: Enter matlabTestManager.

Examples

expand all

Open the MATLABShortestPath project.

openProject("MATLABShortestPath");

Open the MATLAB Test Manager.

matlabTestManager

Run all tests in the project by clicking the Run button run_16.png. Filter the results to only show the failed tests by clicking the Failed button in the test results summary.

The test manager is filtered to show only failed tests. The mouse points to the Failed button in the test results summary.

To create test suites:

  1. Open the Test Suite Manager. In the MATLAB Test Manager menu, click the drop-down list on the left and select Manage Custom Test Suites.

  2. Create a new test suite by clicking New.

  3. Name the test suite by entering text in the Name box.

  4. Specify the tests from the project to include in the test suite:

    • To create a test suite from tests in a folder, select Base Folders. Then, click the Browse button and select the folder. You can select multiple folders by browsing for and selecting folders multiple times.

    • To create a test suite from tests that have a test tag, select Tags. Then, in the box next to Tags, enter a comma-separated list of tags. For more information, see Tag Unit Tests.

    • To create a test suite that includes only the tests that satisfy the conditions of a selector, select Selector. Then, in the box next to Selector, enter the code that creates the selector. You can use logical operators to combine selectors. For a list of selectors, see matlab.unittest.selectors. For example, entering this code creates a test suite that contains tests from the project that are in the Tests folder: HasBaseFolder("tests").

    • To create a test suite based on file or folder dependencies, select Depends On (since R2025a). Select the files or folders by setting the drop-down list next to Depends On to Files or Folder, clicking the Browse button , and selecting the file or folder. You can select multiple files or folders by browsing for and selecting files or folders multiple times.

  5. Click Save.

The Test Suite Manager shows a test suite called Tests folder that is created from tests that are in the tests folder.

To edit test suites, open the Test Suite Manager and select the test suite. Edit the test suite, then click Save.

To delete test suites, open the Test Suite Manager, select the test suite, then click Remove.

To select test suites, click the drop-down list on the left. Under Custom Test Suites, select the test suite.

To run test suites, select a test suite, then click the Run button .

Open the MATLABShortestPath project.

openProject("MATLABShortestPath");

Open the MATLAB Test Manager.

matlabTestManager

Click the Coverage button coverage_16.png, then select Enable code coverage and set the metric level to MC/DC.

The mouse points to the Enable code coverage button, and the setting is enabled.

Run all tests in the project by clicking the Run button run_16.png. The Statement button shows the statement coverage percentage. To view the coverage summary for other coverage metrics, point to the Statement coverage button.

The mouse points to the Statement button, showing the coverage results.

To view the coverage report, click the Statement button, or click the Report button coverage-report_16.png and, under Code Coverage Reports, select the coverage report.

Since R2024b

If you have Embedded Coder®, you can collect code coverage for generated C/C++ code that executes when you run equivalence tests.

To collect code coverage:

  1. Ensure that your equivalence tests use SIL or PIL verification. For more information, see Collect Coverage for Generated C/C++ Code in Equivalence Tests.

  2. Enable generated code coverage by clicking the Code Coverage button and selecting Enable generated code coverage. To configure the test manager to automatically open the generated code coverage report when you run equivalence tests, select Automatically open code coverage report.

  3. Set the coverage metric level to the highest level of coverage that you want to include in the code coverage report.

    Enable generated code coverage is selected in the MATLAB Test Manager.

    When you select a metric level, the report includes the metrics up to and including the selected level. For example, if you select Condition, the report includes the statement, decision, and condition coverage metrics.

  4. Run the equivalence tests.

    • Run all tests in the project by setting the drop-down menu to the left of the Run button to All Tests in Current Project. Then, click the Run button .

    • Run specific equivalence tests by right-clicking the test or test file and selecting Run selected.

  5. To open the code coverage report, click the Report button , then, under Generated Code Coverage Reports, select the report. The MATLAB Test Manager stores the five most recent generated code coverage reports.

    For more information, see Collect Coverage for Generated C/C++ Code in Equivalence Tests.

You can customize your test run by using buttons in the toolstrip:

  • Parallel execution — To use parallel execution, click the Parallel button .

  • Strict checks — To treat warnings as errors, enable strict checks. Click the Settings button , then, in the Test Run Settings dialog box, under Strictness, select Apply strict checks when running tests.

  • Output Detail — To specify the detail level for reported events, click the Settings button , then, in the Test Run Settings dialog box, under Output Detail, clear Use Default and set the output detail level.

  • Logging Level — To specify the maximum level at which logged diagnostics are included by the plugin instance, click the Settings button , then, in the Test Run Settings dialog box, under Logging Level, clear Use Default and set the logging level.

  • Display test failure diagnostics in the Command Window — To display test failure diagnostics in the MATLAB Command Window, next to the Run button , click the Expand icon and select Enable logged diagnostics. (since R2024a)

Note

The MATLAB Test Manager shares test settings with the MATLAB Editor and Test Browser. For more information, see Comparison of Test Settings.

Since R2024b

You can view test and coverage results from the five most recent previous runs. To view a previous run, click the drop-down menu to the left of the Run button and, under Previous Runs, select a run.

The mouse points to a previous run of All Tests in Current Project.

The MATLAB Test Manager opens the test suite, displays the results, and lists the date and time that the suite ran.

The MATLAB Test Manager shows the test results from a previous run.

To view a report associated with the run, click the Report button , then select a report. You can view these reports:

  • To view the coverage report associated with the run, select a report under Code Coverage Reports.

  • To view the generated code coverage report for equivalence tests that generated C/C++ code as a static library and executed in SIL or PIL mode, select a report under Generated Code Coverage Reports.

To generate a report from the test results in the previous run, under Test Result Reports, click Generate Test Result Report.

To navigate to the current test results, click the drop-down menu to the left of the Report button and select All Tests in Current Project or a custom test suite.

Since R2025a

To improve collaboration and save test and coverage results as a reference, you can import and export test runs as JSON files.

To export test runs:

  1. Open a previous test run. In the menu, click the drop-down list on the left, and select the run under Previous Runs.

    The mouse points to a previous run of All Tests in Current Project.

  2. Export the test run by clicking the Export button in the menu.

  3. In the window that appears, save the test run.

The exported JSON file contains the test results. If the tests ran with code coverage or generated code coverage enabled, the JSON file also contains the coverage results.

To import test runs, click the drop-down list in the left of the menu and select Import Test Run. In the window that appears, select the JSON file that contains the test run to import. The MATLAB Test Manager opens the previous run and displays the test suite, the results, and lists the date and time that the suite ran.

For more information, see Import and Export Test Runs From MATLAB Test Manager.

You can add and remove columns in the Test Details table. Click the Column button and select or clear columns.

Note

To add the Requirements column, you must have Requirements Toolbox™ installed.

You can also filter tests by some test types by clicking Filters and then selecting Baseline or Equivalence.

By default, the MATLAB Test Manager lists tests in the Test Details table by ascending load order for each test file. To change how the table lists the tests, point to a column, then click the Sort Up button . To reverse sort, click the Sort Down button . You can also select the column to sort by clicking the three-dot button (since R2024b). The table sorts the tests for each column:

  • Test — Lists the tests by natural sort or by load order. Click the three-dot button and select Test (Natural Sort) or Test (Load Order) to specify the sort type (since R2024b). Sorting by load order lists the tests in the order that the test file defines them. Sorting by natural sort lists the tests in alphabetical order. However, when test names differ only by numbers, natural sort lists the tests in numerical order. For example, natural sort lists the test a2 before the test a11.

  • Diagnostic — Lists the tests alphabetically by diagnostic.

  • Tags — Lists the tests alphabetically by tag name.

  • Requirements — Lists the tests alphabetically by requirement summary.

  • Time — Lists the tests by the test run time length.

Since R2024b

If you have Requirements Toolbox, you can create and delete links from MATLAB tests to requirements.

To create links:

  1. Open the Requirements Editor. On the Apps tab, under Verification, Validation, and Test, click Requirements Editor.

  2. Open a requirement set. For more information, see Create, Open, and Delete Requirement Sets (Requirements Toolbox).

  3. Select a requirement.

  4. In the MATLAB Test Manager, select the test.

  5. Right-click the test and select Requirements > Link to Selection in Requirements Browser.

A test is selected in the is selected in the MATLAB editor.

To delete all links from a test, select the test in the MATLAB Test Manager, then right-click and select Requirements > Delete All Links.

Since R2024b

You can run baseline tests in a project by using the MATLAB Test Manager. For more information about baseline tests, see Create Baseline Tests for MATLAB Code.

The test manager enables you to create baseline data, export test data to the workspace, and update the stored baseline data:

  • To create baseline data for a test that failed because did not have baseline data when it ran, open the failure diagnostics by clicking the hyperlink in the Diagnostic column. Then, click the Create baseline from recorded test data hyperlink to store the actual value as baseline data in a MAT file.

  • To export the actual value and the corresponding baseline data for a failed test to the workspace, open the failure diagnostics by clicking the hyperlink in the Diagnostic column. Then, click the Export test data to workspace hyperlink.

  • To export only the baseline data for a test to the workspace, click the Baseline Data hyperlink in the Data column. To add the Data column to the Test Details table, click the Column button and then select Data.

  • To update the baseline data stored in a MAT file for a failed test, open the failure diagnostics by clicking the hyperlink in the Diagnostic column. Then, click the Update baseline from recorded test data hyperlink. Alternatively, you can select the test in the Test column, and then right-click and select Update baseline data.

Since R2025a

When you run tests by using the MATLAB build tool, you can use test and coverage settings that you specify in the MATLAB Test Manager. Configure the settings in the test manager and then copy a code snippet for the build configuration into your build file. The code snippet specifies the settings for coverage, output detail, logging level, and strict checks, and specifies the tests to run based on the current test suite in the MATLAB Test Manager. To avoid unexpected behavior, do not use the code snippet generated from one project in the build file for a different project.

To generate the code snippet, in the MATLAB Test Manager menu, click the Build Configuration button . In the Copy Current Test Configuration for Build File window, copy the code snippet by clicking the Copy button . Paste the code snippet in a build file. For more information, see Configure Test Settings for Build Tool by Using MATLAB Test Manager.

Version History

Introduced in R2023a

expand all