Skip to content

Latest commit

 

History

History
128 lines (94 loc) · 5.12 KB

File metadata and controls

128 lines (94 loc) · 5.12 KB

MATLAB Testing Framework

Interactive or programmatic testing in MATLAB

This project includes tests which check that models and scripts run without errors and warnings. The main product feature used for testing is MATLAB Testing Frameworks. Specifically, class-based unit test is implemented for each component, BEV system model, and the project.

Test Browser

You can run tests interactively in MATLAB Editor. Open Test Browser (the testBrowser command) to see pass/fail status of the tests as you run tests. Test Browser also lets you measure code coverage.

MATLAB Test Manager

For MATLAB projects, you can also use MATLAB Test Manager to run tests and measure code coverage. It requires the MATLAB Test license. MATLAB Test Manager can find test files in the project and lets you run them all at once or individually.

You can open MATLAB Test Manager from the Project toolstrip or with the matlabTestManager command.

MATLAB Project Toolstrip

MATLAB Test Manager finds the tests in the project and shows the status. By default, MATLAB Test Manager selects "All Tests in Current Project" in the drop down near the top left of the window.

MATLAB Test Manager - All Tests

Select "Impacted Tests Since Last Commit" from the drop down and MATLAB Test Manager updates the list to show tests that are impacted by the changes you have made after the last commit.

MATLAB Test Manager - Impacted Tests

Build Tool with buildfile.m

You can run tests programmatically or interactively. To run tests programmatically, use the buildtool command provided by the MATLAB Build Tool. To run tests interactively, open the buildfile.m file in MATLAB Editor and use the Run Build button in the Editor toolstrip. The Project toolstrip also has a Run Build button which is linked to the buildfile.m file in the project root folder. MATLAB Build Tool supports not only unit test, but also code coverage measurement, code issues checking, custom tasks, building task dependencies, and more.

Code Analyzer

Code Analyzer app (the codeAnalyzer command) can identify issues in the code files.

Code Analyzer is integrated with Build Tool as CodeIssuesTask.

Notes about file name and unit test

If the name of a .m script file starts or ends with test in case-insensitive manner, such as testModel1.m or myScript2Test.m, MATLAB including the Build Tool treats it as a unit test file. This is part of the script-based unit test feature, and such files are automatically run when you run the build tool.

Automated testing in continuous integration

Test files introduced above can be used locally in your machine where you run a test runner script in MATLAB. If you also have a remote repository server for source control (such as GitHub or GitLab), you can use the same test files to automatically test the project when you push local changes to the remote.

If your repository is a public repository in github.com, you can use MATLAB and some toolboxes for free in GitHub Actions Continuous Integration service. There are limits on execution time and resources imposed by GitHub Actions. For more information, see the documentation linked below.

To learn more about Continuous Integration with MATLAB, see the following resources:

Copyright 2023-2025 The MathWorks, Inc.