MATLAB Test Manager
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. View and verify linked requirements.
To add tests to the test manager:
Add a test file to the project. For more information, see Manage Project Files.
Add a
Test
label to the file. For more information, see Add Labels to Project Files.Add tests to the test file. For more information, see Ways to Write Unit Tests.
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 the MATLAB Test Manager.
MATLAB command prompt: Enter
matlabTestManager
.
Examples
Run Tests and Filter Results
Open the MATLABShortestPath
project.
openProject("MATLABShortestPath");
Open the MATLAB Test Manager.
matlabTestManager
Run all tests in the project by clicking the Run button . Filter the results to only show the failed tests by clicking the Failed button in the test results summary.
Create and Run Test Suites
Open the MATLABShortestPath
project.
openProject("MATLABShortestPath");
Open the MATLAB Test Manager.
matlabTestManager
Open the Test Suite Manager by clicking the drop-down to the left of the Run button and selecting Manage Custom Test Suites
. Click New to create a new test suite. Set the Name field to InputTests
.
Select Tags and enter InputTests
in the text box. Click Save, then click Close.
In the MATLAB Test Manager, select the test suite by setting the drop-down to the left of the Run button to InputTests
. Run the tests in the test suite by clicking the Run button .
Collect Code Coverage
Open the MATLABShortestPath
project.
openProject("MATLABShortestPath");
Open the MATLAB Test Manager.
matlabTestManager
Click the Coverage button , then select Enable code coverage and set the metric level to MC/DC.
Run all tests in the project by clicking the Run button . The Statement button shows the statement coverage percentage. To view the coverage summary for other coverage metrics, point to the Statement coverage button.
To view the coverage report, click the Statement button, or click the Report button and, under Code Coverage Reports, select the coverage report.
Collect Code Coverage for Generated C/C++ Code
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:
Ensure that your equivalence tests use SIL or PIL verification. For more information, see Collect Coverage for Generated C/C++ Code in Equivalence Tests.
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.
Set the coverage metric level to the highest level of coverage that you want to include in the code coverage report.
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.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.
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.
Customize Test Run
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.
Note
The MATLAB Test Manager shares test settings with the MATLAB Editor and Test Browser. For more information, see Comparison of Test Settings.
View Test Results from Previous Runs
Since R2024b
You can view test and coverage results from the five most recent previous runs.
To view a previous run, click the button to the left of the Run button and, under Previous Runs, select a run.
The MATLAB Test Manager opens the test suite, displays the results, and lists the date and time that the suite ran.
You can view reports associated with the run by clicking the Report button . Then:
To view the coverage report associated with the run, under Code Coverage Reports, select the report.
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, under Generated Code Coverage Reports, select the report.
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 button to the left of the Report
button and select
All Tests in Current
Project
or a custom test suite.
Add and Remove Columns
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.
Sort Column Entries
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. 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 testa11
.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.
Create and Delete Links to Requirements
Since R2024b
If you have Requirements Toolbox, you can create and delete links from MATLAB tests to requirements.
To create links:
Open the Requirements Editor. On the Apps tab, under Verification, Validation, and Test, click Requirements Editor.
Open a requirement set. For more information, see Create, Open, and Delete Requirement Sets (Requirements Toolbox).
Select a requirement.
In the MATLAB Test Manager, select the test.
Right-click the test and select Requirements > Link to Selection in Requirements Browser.
To delete all links from a test, select the test in the MATLAB Test Manager, then right-click and select Requirements > Delete All Links.
Run Baseline Tests in Projects
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 there was no 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.
Version History
Introduced in R2023aR2024b: View test results from previous runs
View previous runs in the MATLAB Test Manager. The test manager stores the five most recent test runs.
R2024b: Collect coverage for generated C/C++ code in equivalence tests
If you have Embedded Coder, you can use the MATLAB Test Manager to collect coverage for generated C/C++ code that you execute in SIL and PIL equivalence tests. View the coverage results in an HTML report by clicking the Report button , and, under Generated Code Coverage Reports, selecting the report. Alternatively, view a summary of the coverage results in the Code Quality Dashboard.
R2024b: Sort tests in the MATLAB Test Manager
Sort tests in the MATLAB Test Manager by load order or natural sort.
R2024b: Create and delete requirement links in MATLAB Test Manager
If you have Requirements Toolbox, use the MATLAB Test Manager to create and delete links from MATLAB tests to requirements.
R2024b: Run baseline tests in projects
Run baseline tests in projects by using the MATLAB Test Manager. The test manager enables you to create baseline data, export test data to the workspace, and update the stored baseline data.
R2024a: View coverage summary in the MATLAB Test Manager
View a coverage summary for the tests in the current test suite in the MATLAB Test Manager. When you enable coverage, the MATLAB Test Manager displays the Statement button. The Statement button shows the statement coverage percentage for the current test suite. To view the coverage summary for other coverage metrics, point to the Statement button or open the coverage report for the current test suite by clicking the button.
R2024a: Display test failure diagnostics in the Command Window
Display the diagnostics in the MATLAB Command Window for failed tests that you run. Next to the Run button , click the Expand icon and select Enable logged diagnostics.
R2023b: Use the MATLAB Test Manager to verify requirements in the Requirements Editor
Verify requirements in your project by linking them to tests in the project and running the linked tests by using the MATLAB Test Manager. You can then view the requirements verification status in the Requirements Editor (Requirements Toolbox). Similarly, you can update the test results in the MATLAB Test Manager when you run tests by using the Requirements Editor.
R2023b: Generate test reports from test results in the MATLAB Test Manager
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.
R2023b: Collect coverage results for selected tests or test suites by using the MATLAB Test Manager
Collect coverage in the MATLAB Test Manager when you run selected tests or test suites.
R2023b: View tests and results from referenced projects in the MATLAB Test Manager
When a parent project references other projects, the MATLAB Test Manager displays the tests from the parent project and the referenced projects.
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)