Manage Tests and Results by Using the MATLAB Test Manager
Manage MATLAB® tests and test results for Projects by using the MATLAB Test Manager. You can:
Organize tests by creating test suites and using test tags.
Run tests and view a summary of the results.
Investigate test results by viewing failure diagnostics and using filters.
Run subsets of tests by using test suites, test selections, and filters.
Generate test reports from the current test results.
For more information about authoring MATLAB tests, see Ways to Write Unit Tests.
To open the test manager, first open a project. Then, in the Project tab, in the Tools menu, under Apps, click MATLAB Test Manager.Organize Tests
The MATLAB Test Manager displays tests in the currently open project and
its referenced projects that have the Test
label. For more
information, see Add Labels to Project Files. Organize your
tests by using test suites and test tags.
Test Suites
Test suites are groups of tests that share common criteria. You can create and save test suites by using the Test Suite Manager. For more information, see Create and Run Test Suites.
You can create test suites from:
Tests in a folder
Tests that have a specific test tag or tests from multiple tags
Selectors by using constructors for classes in
matlab.unittest.selectors
ormatlabtest.selectors
Tip
If your parent project references other projects, you can create a test
suite that contains only the tests in a referenced project by using the
Base Folders radio button or the matlab.unittest.selectors.HasBaseFolder
selector to select the
folder that contains the referenced project.
Test Tags
Use test tags to group tests into categories. Typical test tags identify a feature about the code under test or describe the type of test. For more information, see Tag Unit Tests.
Run Tests and View Results
To run all tests in the project, click the Run button .
You can use the MATLAB Test Manager to collect coverage for M, MLX, and MLAPP files in the project that have the Design
label. For more information, see Add Labels to Project Files. For more information about collecting coverage, see MATLAB Test Manager in Interactively Collect Code Coverage.
You can customize your run by setting test options. For more information, see Customize Test Run.
The MATLAB Test Manager displays the test results from the last time each test was run. Test results include status, duration, and a diagnostic for failed and incomplete tests.
The test result summary aggregates the status of the tests in the project or test suite from the last time the tests were run. The Test Details table displays detailed test results.
Tests in the test manager have one of these statuses:
Status | Definition | Cause |
---|---|---|
Passed | The test completed without failures. | – |
Failed | The test caused at least one failure or error to occur. | The test failed because of a:
|
Incomplete | The test did not run to completion. | The test did not run to completion because of an assumption failure:
For more information, see |
Not Run | The test has not run. |
|
For more information about qualifications, see Table of Verifications, Assertions, and Other Qualifications.
Investigate Test Results
Use the Test Details table to view details about the test results. Investigate test results by using filters to view:
Only the failed tests
Tests that have a specific failure diagnostic
Results for tests with specific tags
Results for tests linked to specific requirements
Investigate failed tests by using information in the Test Details table.
Filter Test Results
To filter tests by test results, click the Passed, Failed, Incomplete, or Not Run buttons in the test result summary. Alternatively, above the Test Details table, click the Filters button and select which test results to filter by.
To filter by text, enter text in the Filter by text box. This filter searches the table and returns only the rows that contain the search term.
Investigate Failed Tests
To investigate and fix failed tests:
View the failure diagnostic by clicking the hyperlink in the Diagnostic column. You can view detailed diagnostics by clicking the
FAIL
hyperlink.Open the failed test in the MATLAB Editor by clicking the test hyperlink in the failure diagnostic or in the Test column of the Test Details table.
Fix the test failure by making changes to the test or to the source code under test. For more information, see Analyze Failed Test Results.
Tip
Run the test without leaving the editor by using the Test Browser. For more information, see Run MATLAB Tests.
Run the fixed test and other related tests by using the MATLAB Test Manager.
Run Subsets of Tests
When you add new tests or fix failed tests, you can run only the relevant tests by:
Running a test suite
Running a single test or test file
Running a selection of multiple tests
Applying filters and running a selection of tests
Run Test Suites
To open a test suite, click All Tests in Current Project, then select a test suite from the menu.
To run all tests in the test suite, click the Run button .
Run Selected Tests
To run a single test or all tests in a single file, right-click the test or test file and select Run selected. Alternatively, next to the Run button , click the Expand icon and select Run selected.
To run a selection of multiple tests, press Shift or Ctrl and select the tests, then right-click and select Run selected.
Run Filtered Tests
To run a subset of tests by using filters:
Apply a filter to the project or test suite. For more information about filtering tests, see Filter Test Results.
Press Shift or Ctrl and select the filtered tests.
Right-click the selection and select Run selected.
Note
Clicking the Run button runs all tests in the project or test suite even when filters are applied.
Report Test Results
You can generate test reports from the current test results in the MATLAB Test Manager for all tests in the project, for the tests in a test suite, or for selected tests. You can generate the test report as a PDF, HTML, or DOCX file.
To generate a test report for all tests in the project:
Click the Report button and, under Test Result Reports, select Generate Test Result Report.
Note
If some of the tests do not have test results, a dialog box lists the tests that do not have results. To generate the report only for tests that have results, click Continue.
In the dialog box, choose a location to save the test report.
Enter the file name for the test report.
Choose the file type for the test report.
Click Save.
MATLAB opens the report after it generates.
To generate test reports for the tests in a specific test suite, select the test suite from the drop-down menu to the left of the Run button , then generate the report.
To generate test reports for specific tests, press Shift or Ctrl to select the tests, then click the Report button and, under Test Result Reports, select Generate Test Result Report for Selected Tests.