Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 2db4f26

Browse files
authored
Merge pull request #31 from mathworks/readme_revision
Readme revision
2 parents 0f150a8 + fb6e35f commit 2db4f26

File tree

2 files changed

+92
-46
lines changed

2 files changed

+92
-46
lines changed

README.md

Lines changed: 38 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,105 @@
11
# Jenkins MATLAB Plugin
22

3-
## Description
4-
The Jenkins plugin for MATLAB® enables you to easily run your MATLAB tests and generate test artifacts in formats such as JUnit, TAP, and Cobertura code coverage reports.
5-
## Build Step Configuration
6-
To invoke this plugin, select "Run MATLAB Tests" from the Add build step list.
3+
The Jenkins plugin for MATLAB® enables you to easily run your MATLAB tests and generate test artifacts in formats such as *JUnit*, *TAP*, and *Cobertura* code coverage reports. This guide shows you examples of how to configure the plugin for different objectives, considering a Microsoft® Windows® platform.
4+
5+
## Configure Plugin for Freestyle Project
6+
To configure the plugin for a freestyle project, select **Run MATLAB Tests** from the **Add build step** list. Then, enter the value returned by the **matlabroot** function in the **MATLAB root** field.
77

88
![new_add_build_step](https://user-images.githubusercontent.com/47204011/55624172-be54a100-57c2-11e9-9596-52d3a60ee467.png)
99

10-
![new_default_plugin_page](https://user-images.githubusercontent.com/47204011/55624213-dcba9c80-57c2-11e9-85e6-abb6ae03534e.png)
11-
12-
Use the plugin as part of the Jenkins build step to run MATLAB tests in two distinct modes:
13-
* Automatic
14-
* Custom
15-
16-
Enter the value returned by “matlabroot” in the field named “MATLAB root”.
17-
1810
![new_enter_matlabroot](https://user-images.githubusercontent.com/47204011/55624374-45097e00-57c3-11e9-96e1-5fa0fc966767.png)
1911

20-
#### Configuring “Automatic” Option
21-
This option finds tests written using the MATLAB unit testing framework and/or Simulink Test and runs them. If the code is organized using projects, it will locate all test files in the project that have been classified as "Test". If the code does not leverage projects or uses a MATLAB version prior to R2019a, the plugin will discover all tests in the current Jenkins workspace including subfolders.
12+
### Option 1: Freestyle Project with Automatic Test Mode
13+
With the Jenkins plugin for MATLAB, you have the option to run your tests in either *automatic* or *custom* mode. The automatic test mode employs a default setting to run tests written using the MATLAB Unit Testing Framework and/or Simulink® Test. If your source code is organized as files and folders within a project, the plugin will consider any test files in the project that have been tagged as **Test**. If your code does not leverage a project or uses a MATLAB version prior to R2019a, the plugin will consider all tests in the current Jenkins workspace including the subfolders.
2214

23-
If you are using a source code management (SCM) system such as Git, then the job must include an appropriate SCM configuration to check out the code before running the MATLAB plugin. If you do not use any SCM systems to manage your code, then an additional build step is required to ensure the code is available in the workspace before running the MATLAB plugin.
15+
If you use a source code management (SCM) system such as Git, then your job must include the appropriate SCM configuration to check out the code before it can invoke the MATLAB plugin. If you do not use any SCM systems to manage your code, then an additional build step is required to ensure that the code is available in the Jenkins workspace before the build starts.
2416

25-
The automatic test running feature enables you to generate different types of test artifacts. They could be used with other Jenkins plugins as part of a post-build action to publish the test results. To configure the Jenkins build for running MATLAB tests automatically, follow these steps.
17+
The automatic test execution feature of the plugin enables you to generate different types of test artifacts. To publish the test results, you can use these artifacts with other Jenkins plugins. To configure the Jenkins build where MATLAB tests run automatically, follow these steps.
2618

27-
1) Select the Test mode as Automatic to run tests (Automatic is the default mode).
19+
1) From the **Test mode** drop-down list, select the **Automatic** option (**Automatic** is the default testing mode).
2820

2921
![new_select_automatic_option](https://user-images.githubusercontent.com/47204011/55624469-a0d40700-57c3-11e9-8811-32892ccbe673.png)
3022

31-
2) Select the desired test artifacts. You can also choose not to generate any test artifacts.
23+
2) Select your desired test artifacts.
3224

3325
![new_select_all_test_artifacts](https://user-images.githubusercontent.com/47204011/55624765-7f274f80-57c4-11e9-8a15-ebdef19ebd3d.png)
3426

35-
The selected test artifact(s) will be stored in the matlabTestArtifacts folder of the Jenkins workspace.
27+
The selected artifacts will be saved in the **matlabTestArtifacts** folder of the Jenkins workspace.
3628

3729
![Workspace01](https://user-images.githubusercontent.com/47204011/55470859-1e621080-5626-11e9-98f2-044144272643.JPG)
3830

3931
![Test_artifacts](https://user-images.githubusercontent.com/47204011/55470863-21f59780-5626-11e9-9765-4d79a6fd4061.JPG)
4032

41-
If the user does not select any test artifact generation checkboxes, this folder will not be created under the workspace and no test artifacts will be generated. However, test execution still occurs and test failures will fail the build.
33+
If you do not select any of the test artifact check boxes, the **matlabTestArtifacts** folder will not be created in the workspace. However, tests will still run and potential test failures will fail the build.
4234

43-
The Automatic test run mode generates a MATLAB script file named runMatlabTests.m in the Jenkins workspace. The plugin uses this file to run tests and generate test artifacts. You may review the MATLAB script to understand the test workflow.
35+
The **Automatic** test mode results in a MATLAB script file named **runMatlabTests.m** in the Jenkins workspace. The plugin uses this file to run the tests and generate the test artifacts. You can review the contents of the script to understand the testing workflow.
4436

4537
![Workspace01](https://user-images.githubusercontent.com/47204011/55470859-1e621080-5626-11e9-98f2-044144272643.JPG)
4638

39+
### Option 2: Freestyle Project with Custom Test Mode
40+
This option enables you to develop your custom MATLAB commands for running tests. To configure the Jenkins build where you can customize the MATLAB test execution, follow these steps.
4741

48-
#### Configuring “Custom” Option
49-
This option enables you to develop your custom MATLAB commands for running tests.
50-
51-
1) From the "Test mode" dropdown list, select “Custom” option.
42+
1) From the **Test mode** drop-down list, select the **Custom** option.
5243

5344
![new_select_custom](https://user-images.githubusercontent.com/47204011/55624858-d0cfda00-57c4-11e9-8366-45edbc9ba83f.png)
5445

55-
2) In "MATLAB command” text box, enter your MATLAB command. Separate multiple commands by commas or semicolons.
46+
2) Enter your commands in the **MATLAB command** field. If you specify more than one MATLAB command, use a comma or semicolon to separate the commands. The build will fail if the execution of any command results in an error.
5647

5748
![new_custom_runtest_command](https://user-images.githubusercontent.com/47204011/55624949-096fb380-57c5-11e9-8711-98baf91816c0.png)
5849

59-
Note: If you require several MATLAB commands to execute your test session, consider writing a MATLAB script or function as part of your repository and executing the script or function instead. Test artifacts are not autogenerated if you choose to run tests using your custom MATLAB commands. You can generate these and other artifacts by configuring a test runner in the script or function invoked by the command. The build will fail if the execution of any MATLAB command causes an error.
50+
**Note:** If you need several MATLAB commands to run your tests, consider writing a MATLAB script or function as part of your repository and executing this script or function instead. Test artifacts are not autogenerated if you choose to run tests using custom MATLAB commands. You can generate your desired test artifacts by configuring the test runner in the script or function that you invoke from the **MATLAB command** field.
6051

6152
![new_custom_script_example](https://user-images.githubusercontent.com/47204011/55625021-32904400-57c5-11e9-86b7-478b930796c0.png)
6253

63-
## Configuring "Multi-configuration"(matrix) project.
64-
The Jenkins plugin for MATLAB can be used inside of "Multi-configuration" (matrix) projects. Matrix projects allow jobs to be repeated with different configurations, such as testing on multiple platforms or testing against multiple MATLAB versions.
54+
## Configure Plugin for Multi-Configuration Project
55+
In addition to freestyle projects, the Jenkins plugin for MATLAB supports [multi-configuration (matrix) projects](https://wiki.jenkins.io/display/JENKINS/Building+a+matrix+project). Multi-configuration projects are useful when builds include similar steps, for example when the same test suite should run on different platforms (e.g., Windows, Linux, and Mac) or using several MATLAB versions.
6556

66-
#### Matrix build for "Automatic" option.
57+
![image](https://user-images.githubusercontent.com/47204011/62458632-0e586a00-b79b-11e9-8611-3671adb8c289.png)
6758

68-
1) Create a "Multi-configuration" project.
59+
As in a freestyle project, you can run your tests in automatic or custom mode within a multi-configuration project. The configuration requires you to specify the location where MATLAB is installed as well as the test execution mode. You should also add user-defined axes in the **Configuration Matrix** to specify the duplicating build steps.
6960

70-
![image](https://user-images.githubusercontent.com/47204011/62458632-0e586a00-b79b-11e9-8611-3671adb8c289.png)
61+
### Option 1: Multi-Configuration Project with Automatic Test Mode
62+
63+
To configure the plugin for a matrix build where tests run automatically in multiple MATLAB versions, create a multi-configuration project and follow these steps.
7164

72-
2) Add User-defined axis for different MATLAB versions as shown below.
65+
1) Add a user-defined axis in the **Configuration Matrix** to represent the MATLAB versions in the build. Specify the name of the axis in the **Name** field and its values in the **Values** field. Separate the elements in the **Values** field with a space. In this example, four MATLAB versions are specified, which will be used to run the same set of tests.
7366

7467
![image](https://user-images.githubusercontent.com/47204011/62603081-c2c8cc00-b912-11e9-83a4-c5462f58f607.png)
7568

76-
3) Replace the User-defined axis variable in MATLAB root appropriately.
69+
2) In the **Run MATLAB Tests** section of the project, include the user-defined axis name in the **MATLAB root** field to specify the locations where MATLAB is installed. In this example, **$VERSION** will be replaced by one axis value per build step.
7770

7871
![image](https://user-images.githubusercontent.com/47204011/62459137-3c8a7980-b79c-11e9-9bee-305b4cabfd42.png)
7972

80-
4) Save and run the build.
73+
You can select the test artifact check boxes when tests run automatically. Once you have made your selections, save your settings and run the build.
8174

82-
#### Matrix build for "Custom" option.
75+
### Option 2: Multi-Configuration Project with Custom Test Mode
8376

84-
1) Create a "Multi-configuration" project.
85-
86-
![image](https://user-images.githubusercontent.com/47204011/62458632-0e586a00-b79b-11e9-8611-3671adb8c289.png)
77+
To configure the matrix build where you can customize the MATLAB test execution, create a multi-configuration project and follow these steps.
8778

88-
2) Add User-defined axis for different MATLAB versions as shown below.
79+
1) Add a user-defined axis in the **Configuration Matrix** to represent the MATLAB versions in the build.
8980

9081
![image](https://user-images.githubusercontent.com/47204011/62603081-c2c8cc00-b912-11e9-83a4-c5462f58f607.png)
9182

92-
3) Add another User-defined axis for custom commands as shown below.
83+
2) Add another user-defined axis using the **Add axis** button. In this example, the **TEST_TAG** axis specifies the possible test tags for a group of test elements.
9384

9485
![image](https://user-images.githubusercontent.com/47204011/62517774-b6c30880-b845-11e9-86a0-8344a281fb27.png)
9586

96-
4) Replace the User-defined axis variable in MATLAB root appropriately.
87+
3) In the **Run MATLAB Tests** section of the project, use the **VERSION** axis to specify the locations where MATLAB is installed.
9788

9889
![image](https://user-images.githubusercontent.com/47204011/62459137-3c8a7980-b79c-11e9-9bee-305b4cabfd42.png)
9990

100-
5) Select "Custom" option from "Test mode" drop-down and replace User-defined axis variable for custom command appropriately.
91+
4) From the **Test mode** drop-down list, select the **Custom** option. Use the second user-defined axis to create your commands and enter them in the **MATLAB command** field. Then, save your settings and run the build.
10192

10293
![image](https://user-images.githubusercontent.com/47204011/62686681-cd529680-b9e2-11e9-82c1-c211f1740be4.png)
10394

104-
6) Save and run the build.
95+
**Notes:**
96+
1) For a user-defined axis named **VAR**, **$VAR** and **${VAR}** are both valid formats for accessing the values.
10597

98+
2) A multi-configuration project creates a separate workspace for each user-defined axis value. If you specify the full paths to where MATLAB is installed as axis values, Jenkins fails to create separate workspaces and fails the build.
10699

107-
Note: Axis variables can be replaced in either "$VAR" or "${VAR}" formats. Do not use complete MATLAB root path as axis values. Multi-configuration project creates separate workspace folder for each User-defined axis values with same name, and file separators in complete path will cause Jenkins build to fail as folder creation fails.
108100

109101
## Contact Us
110-
If you have any questions or suggestions, please feel free to contact MathWorks.
102+
If you have any questions or suggestions, please contact MathWorks.
111103

112104
113105

TestRand.m

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
classdef TestRand < matlab.unittest.TestCase
2+
properties (ClassSetupParameter)
3+
generator = {'twister','combRecursive','multFibonacci'};
4+
end
5+
6+
properties (MethodSetupParameter)
7+
seed = {0, 123, 4294967295};
8+
end
9+
10+
properties (TestParameter)
11+
dim1 = struct('small', 1,'medium', 2, 'large', 3);
12+
dim2 = struct('small', 2,'medium', 3, 'large', 4);
13+
dim3 = struct('small', 3,'medium', 4, 'large', 5);
14+
type = {'single','double'};
15+
end
16+
17+
methods (TestClassSetup)
18+
function ClassSetup(testCase, generator)
19+
orig = rng;
20+
testCase.addTeardown(@rng, orig)
21+
rng(0, generator)
22+
end
23+
end
24+
25+
methods (TestMethodSetup)
26+
function MethodSetup(testCase, seed)
27+
orig = rng;
28+
testCase.addTeardown(@rng, orig)
29+
rng(seed)
30+
end
31+
end
32+
33+
methods (Test, ParameterCombination='sequential')
34+
function testSize(testCase,dim1,dim2,dim3)
35+
testCase.verifySize(rand(dim1,dim2,dim3),[dim1 dim2 dim3])
36+
end
37+
end
38+
39+
methods (Test, ParameterCombination='pairwise')
40+
function testRepeatable(testCase,dim1,dim2,dim3)
41+
state = rng;
42+
firstRun = rand(dim1,dim2,dim3);
43+
rng(state)
44+
secondRun = rand(dim1,dim2,dim3);
45+
testCase.verifyEqual(firstRun,secondRun);
46+
end
47+
end
48+
49+
methods (Test)
50+
function testClass(testCase,dim1,dim2,type)
51+
testCase.verifyClass(rand(dim1,dim2,type), type)
52+
end
53+
end
54+
end

0 commit comments

Comments
 (0)