Run MATLAB Tests on Jenkins Server

April 8, 2026 · View on GitHub

This example shows how to run a suite of MATLAB® unit tests with Jenkins™. The example demonstrates how to:

  • Configure a freestyle project to access MATLAB tests hosted in a remote repository.
  • Add a build step to the project to run the tests and generate test and coverage artifacts.
  • Build the project and examine the test results and the generated artifacts.

The freestyle project runs the tests in the Times Table App MATLAB project (which requires R2019a or later). You can create a working copy of the project files and open the project in MATLAB by running a statement in the Command Window. The statement to run depends on your MATLAB release:

R2023a and EarlierStarting in R2023b
matlab.project.example.timesTableopenExample("matlab/TimesTableProjectExample")

For more information about the Times Table App project, see Explore an Example Project.

Prerequisites

To follow the steps in this example:

  • MATLAB and the plugin for MATLAB must be installed on your Jenkins server. For information on how to install a plugin in Jenkins, see Managing Plugins.
  • The Times Table App project must be under source control. For example, you can create a new repository for the project using your GitHub® account. For more information, see Use Source Control with Projects.
  • The coverage and JUnit plugins must be installed. These plugins are required to publish the artifacts using post-build actions.

Create a Freestyle Project to Run MATLAB Tests

Create a new project and configure it by following these steps:

  1. In your Jenkins interface, select New Item on the left. A new page opens where you can choose the type of your project. Enter a project name, and then click Freestyle project. To confirm your choices, click OK.

Project creation interface showing Freestyle project selected as the project type and myProject entered as the project name

  1. On the project configuration page, in the Source Code Management section, specify the repository that hosts your tests.

Source Code Management section of the project configuration page with the Repository URL box populated with a GitHub repository URL and the Branch Specifier box specifying the main branch

  1. In the Environment section, select Use MATLAB version and specify the MATLAB version you want to use in the build. If your preferred MATLAB version is not listed under Use MATLAB version, enter the full path to its root folder in the MATLAB root box.

Environment section showing Use MATLAB version selected with Custom chosen from the drop‑down list, and the MATLAB root box populated with the absolute path to the R2024b MATLAB root folder

  1. In the Build Steps section, select Add build step > Run MATLAB Tests. Then, specify the artifacts to generate in the project workspace. In this example, the plugin generates test results in JUnit-style XML format and code coverage results in Cobertura XML format. Furthermore, to generate the coverage results, the plugin uses only the code in the source folder located in the root of the repository. For more information about the build steps provided by the plugin, see Plugin Configuration Guide.
Generate Test Artifacts and Generate Coverage Artifacts sections of the Run MATLAB Tests step with the JUnit‑style test results and Cobertura code coverage options selected
  1. In the Post-build Actions section, add the Publish JUnit test result report post-build action to publish the test results in JUnit-style XML format. Specify the path to the test report in the Test report XMLs box.

Post‑build Actions section showing the Publish JUnit test result report action, with the Test report XMLs box populated with the JUnit‑style test results path specified in the Run MATLAB Tests step

  1. In the Post-build Actions section, add the Record code coverage results post-build action to publish the code coverage results in Cobertura XML format. Select Cobertura Coverage Reports from the Coverage Parser list and specify the path to the coverage report in the Report File Pattern box.

Record code coverage results post‑build action with Cobertura Coverage Reports selected from the Coverage Parser list and the Report File Pattern box populated with the Cobertura code coverage results path specified in the Run MATLAB Tests step

  1. Click Save to save the project configuration settings. You can access and modify your settings at a later stage by selecting Configure in the project interface, which displays the project name at the upper-left corner of the page.

Run Tests and Inspect Artifacts

To build your freestyle project, select Build Now in the project interface. Jenkins triggers a build, assigns it a number under Builds, and runs the build. In this example, the build succeeds because all the tests in the Times Table App project pass.

Navigate to the project workspace by selecting Workspace in the project interface. The generated artifacts are in the matlabTestArtifacts folder of the workspace.

Project interface after selecting Workspace in the left navigation pane, showing links to the generated artifacts

Select Status in the project interface. You can access the published artifacts by clicking the Latest Test Result and Coverage Report links. For example, click the Latest Test Result link to view the published JUnit-style test results. On the test results page, click the (root) link in the All Tests table. The table expands and lists information for each of the test classes within the Times Table App project.

Test results page indicating that all tests passed, with the All Tests table showing information about the three test classes in the MATLAB project

See Also