Manage Tests and Results by Using the MATLAB Test Manager - MATLAB & Simulink (original) (raw)

Manage MATLAB® tests and test results for Projects by using the MATLAB Test Manager. You can:

For more information about authoring MATLAB tests, see Ways to Write Unit Tests. To open the test manager, first open a project. Then, in theProject tab, in the Tools menu, underApps, 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, Manage, and Run Test Suites.

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

You can create test suites from:

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 theBase 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, seeTag 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.

MATLAB Test Manager window with 14 passed tests and 1 failed test spread across 2 test files.

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: Verification failureAssertion failureFatal assertion failureSyntax error in the test or source code that the test called
Incomplete The test did not run to completion. The test did not run to completion because of an assumption failure: In the test function.In the method-level setup or teardown for the test function.In the class-level setup or teardown. The test manager marked all tests in the test file as incomplete.For more information, see matlab.unittest.qualifications.Assumable.
Not Run The test has not run. You have not run this test.You ran the test, but a fatal assertion failure occurred before this test was run. The failure caused the test manager to abort the test run. For more information, see matlab.unittest.qualifications.FatalAssertable.

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:

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, orNot Run buttons in the test result summary. Alternatively, above the Test Details table, click theFilters 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:

  1. View the failure diagnostic by clicking the hyperlink in theDiagnostic column. You can view detailed diagnostics by clicking the FAIL hyperlink.
  2. Open the failed test in the MATLAB Editor by clicking the test hyperlink in the failure diagnostic or in the Test column of theTest Details table.
  3. 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.
  4. 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:

Run Test Suites

To open a test suite, click the drop-down to the left of the Run button and select a test suite from the menu.

To run the 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 orCtrl and select the tests, then right-click and selectRun selected.

Run Filtered Tests

To run a subset of tests by using filters:

  1. Apply a filter to the project or test suite. For more information about filtering tests, see Filter Test Results.
  2. Press Shift or Ctrl and select the filtered tests.
  3. 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

Since R2023b

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:

  1. 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.
  2. In the dialog box, choose a location to save the test report.
  3. Enter the file name for the test report.
  4. Choose the file type for the test report.
  5. Click Save.

MATLAB opens the report after it generates.

The cover page of the MATLAB Test Report shows a pie chart that indicates the project has 14 passed tests and 1 failed test.

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 orCtrl to select the tests, then click the Report button and, under Test Result Reports, select Generate Test Result Report for Selected Tests.

The mouse points to the Generate Test Result Report for Selected Tests menu option.

See Also

Apps

Functions

Topics