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

Commit 323d237

Browse files
authored
Merge pull request #58 from mathworks/DATF-1988-add-pdfTestReport
Adding PDF test report option for non-mac platforms
2 parents d81b8af + 1098f21 commit 323d237

File tree

8 files changed

+53
-26
lines changed

8 files changed

+53
-26
lines changed

CONFIGDOC.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ To configure the plugin for a freestyle project, select **Run MATLAB Tests** fro
1212

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

15-
![new_enter_matlabroot](https://user-images.githubusercontent.com/51316279/70772996-28830400-1d9c-11ea-92d1-db9f054c304c.png)
15+
![new_enter_matlabroot](https://user-images.githubusercontent.com/51316279/72131234-a5a49780-33a1-11ea-8497-45a1d9161ecf.png)
1616

1717
### Option 1: Freestyle Project with Automatic Test Mode
1818
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.
@@ -23,30 +23,32 @@ The automatic test execution feature of the plugin enables you to generate diffe
2323

2424
1) From the **Test mode** drop-down list, select the **Automatic** option (**Automatic** is the default testing mode).
2525

26-
![new_select_automatic_option](https://user-images.githubusercontent.com/51316279/70773784-6719be00-1d9e-11ea-9a6c-7b277d63e10a.png)
26+
![new_select_automatic_option](https://user-images.githubusercontent.com/51316279/72131293-cc62ce00-33a1-11ea-9573-813ac3060790.png)
2727

2828
2) Select your desired test artifacts.
2929

30-
![new_select_all_test_artifacts](https://user-images.githubusercontent.com/51316279/70773293-0dfd5a80-1d9d-11ea-8d24-28407e67c8a5.png)
30+
![new_select_all_test_artifacts](https://user-images.githubusercontent.com/51316279/72131319-e3a1bb80-33a1-11ea-99de-aef714bb5300.png)
3131

3232
The selected artifacts will be saved in the **matlabTestArtifacts** folder of the Jenkins workspace.
3333

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

36-
![Test_artifacts](https://user-images.githubusercontent.com/51316279/70776181-5bc89180-1da2-11ea-92e6-4c71deab7199.png)
36+
![Test_artifacts](https://user-images.githubusercontent.com/51316279/72140084-f625f000-33b5-11ea-8fd6-a4ebde6fcc5f.png)
3737

3838
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.
3939

4040
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.
4141

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

44+
**Note:** Producing a PDF test report is not currently supported on MacOS platforms.
45+
4446
### Option 2: Freestyle Project with Custom Test Mode
4547
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.
4648

4749
1) From the **Test mode** drop-down list, select the **Custom** option.
4850

49-
![new_select_custom](https://user-images.githubusercontent.com/51316279/70775386-42731580-1da1-11ea-9523-41c83443ee5b.png)
51+
![new_select_custom](https://user-images.githubusercontent.com/51316279/72131434-31b6bf00-33a2-11ea-99da-a479dd76f826.png)
5052

5153
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.
5254

@@ -69,33 +71,35 @@ To configure the plugin for a matrix build where tests run automatically in mult
6971

7072
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.
7173

72-
![image](https://user-images.githubusercontent.com/47204011/62603081-c2c8cc00-b912-11e9-83a4-c5462f58f607.png)
74+
![image](https://user-images.githubusercontent.com/51316279/72132482-139e8e00-33a5-11ea-9d94-b8381c5dceca.png)
7375

7476
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.
7577

76-
![image](https://user-images.githubusercontent.com/51316279/70773424-72b8b500-1d9d-11ea-97ca-807ecd6c4e47.png)
78+
![image](https://user-images.githubusercontent.com/51316279/72131571-aee23400-33a2-11ea-8e76-4b36274b9d5b.png)
7779

7880
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.
7981

82+
**Note:** Producing a PDF test report is not currently supported on MacOS platforms.
83+
8084
### Option 2: Multi-Configuration Project with Custom Test Mode
8185

8286
To configure the matrix build where you can customize the MATLAB test execution, create a multi-configuration project and follow these steps.
8387

8488
1) Add a user-defined axis in the **Configuration Matrix** to represent the MATLAB versions in the build.
8589

86-
![image](https://user-images.githubusercontent.com/47204011/62603081-c2c8cc00-b912-11e9-83a4-c5462f58f607.png)
90+
![image](https://user-images.githubusercontent.com/51316279/72132482-139e8e00-33a5-11ea-9d94-b8381c5dceca.png)
8791

8892
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.
8993

90-
![image](https://user-images.githubusercontent.com/47204011/62517774-b6c30880-b845-11e9-86a0-8344a281fb27.png)
94+
![image](https://user-images.githubusercontent.com/51316279/72131623-d6d19780-33a2-11ea-9205-577d6634a1a6.png)
9195

9296
3) In the **Run MATLAB Tests** section of the project, use the **VERSION** axis to specify the locations where MATLAB is installed.
9397

94-
![image](https://user-images.githubusercontent.com/51316279/70773424-72b8b500-1d9d-11ea-97ca-807ecd6c4e47.png)
98+
![image](https://user-images.githubusercontent.com/51316279/72131668-ef41b200-33a2-11ea-9f97-d9476ae0431a.png)
9599

96100
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.
97101

98-
![image](https://user-images.githubusercontent.com/47204011/62686681-cd529680-b9e2-11e9-82c1-c211f1740be4.png)
102+
![image](https://user-images.githubusercontent.com/51316279/72131696-04b6dc00-33a3-11ea-876f-5cdff3a027b4.png)
99103

100104
**Notes:**
101105
1) For a user-defined axis named **VAR**, **$VAR** and **${VAR}** are both valid formats for accessing the values.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Jenkins MATLAB Plugin
22

3-
The Jenkins plugin for MATLAB® enables you to easily run your MATLAB and Simulink® tests and generate artifacts such as *JUnit* and *TAP* test results, and *Cobertura* code or model coverage reports. You can also export your Simulink Test™ Manager results. This guide shows you examples of how to configure the plugin for different objectives, considering a Microsoft® Windows® platform.
3+
The Jenkins plugin for MATLAB® enables you to easily run your MATLAB and Simulink® tests and generate artifacts such as *PDF* test reports, *JUnit* and *TAP* test results, and *Cobertura* code or model coverage reports. You can also export your Simulink Test™ Manager results. This guide shows you examples of how to configure the plugin for different objectives, considering a Microsoft® Windows® platform.
44

55
## Documentation
66

src/main/java/com/mathworks/ci/MatlabBuilder.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.mathworks.ci;
22

33
/*
4-
* Copyright 2019 The MathWorks, Inc.
4+
* Copyright 2019-2020 The MathWorks, Inc.
55
*
66
* This is Matlab Builder class which describes the build step and its components. Builder displays
77
* Build step As "Run MATLAB Tests" under Build steps. Author : Nikhil Bhoski email :
@@ -347,6 +347,7 @@ public static class RunTestsAutomaticallyOption extends TestRunTypeList {
347347
private boolean taCoberturaChkBx;
348348
private boolean taSTMResultsChkBx;
349349
private boolean taModelCoverageChkBx;
350+
private boolean taPDFReportChkBx;
350351

351352
@DataBoundConstructor
352353
public RunTestsAutomaticallyOption() {
@@ -378,6 +379,11 @@ public void setTaModelCoverageChkBx(boolean taModelCoverageChkBx) {
378379
this.taModelCoverageChkBx = taModelCoverageChkBx;
379380
}
380381

382+
@DataBoundSetter
383+
public void setTaPDFReportChkBx(boolean taPDFReportChkBx) {
384+
this.taPDFReportChkBx = taPDFReportChkBx;
385+
}
386+
381387
public boolean getTatapChkBx() {
382388
return tatapChkBx;
383389
}
@@ -398,6 +404,10 @@ public boolean getTaModelCoverageChkBx() {
398404
return taModelCoverageChkBx;
399405
}
400406

407+
public boolean getTaPDFReportChkBx() {
408+
return taPDFReportChkBx;
409+
}
410+
401411
@Extension
402412
public static final class DescriptorImpl extends TestRunTypeDescriptor {
403413
@Override
@@ -419,6 +429,8 @@ public boolean getBooleanByName(String memberName) {
419429
return this.getTaSTMResultsChkBx();
420430
case "taModelCoverageChkBx":
421431
return this.getTaModelCoverageChkBx();
432+
case "taPDFReportChkBx":
433+
return this.getTaPDFReportChkBx();
422434
default:
423435
return false;
424436
}
@@ -611,13 +623,14 @@ private String getNodeSpecificFileSeperator(Launcher launcher) {
611623

612624
// Concatenate the input arguments
613625
private String getInputArguments() {
626+
String pdfReport = MatlabBuilderConstants.PDF_REPORT + "," + getTestRunTypeList().getBooleanByName("taPDFReportChkBx");
614627
String tapResults = MatlabBuilderConstants.TAP_RESULTS + "," + getTestRunTypeList().getBooleanByName("tatapChkBx");
615628
String junitResults = MatlabBuilderConstants.JUNIT_RESULTS + "," + getTestRunTypeList().getBooleanByName("taJunitChkBx");
616629
String stmResults = MatlabBuilderConstants.STM_RESULTS + "," + getTestRunTypeList().getBooleanByName("taSTMResultsChkBx");
617630
String coberturaCodeCoverage = MatlabBuilderConstants.COBERTURA_CODE_COVERAGE + "," + getTestRunTypeList().getBooleanByName("taCoberturaChkBx");
618631
String coberturaModelCoverage = MatlabBuilderConstants.COBERTURA_MODEL_COVERAGE + "," + getTestRunTypeList().getBooleanByName("taModelCoverageChkBx");
619632

620-
String inputArgsToMatlabFcn = tapResults + "," + junitResults + ","
633+
String inputArgsToMatlabFcn = pdfReport + "," + tapResults + "," + junitResults + ","
621634
+ stmResults + "," + coberturaCodeCoverage + "," + coberturaModelCoverage;
622635

623636
return inputArgsToMatlabFcn;

src/main/java/com/mathworks/ci/MatlabBuilderConstants.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.mathworks.ci;
22
/*
3-
* Copyright 2019 The MathWorks, Inc.
3+
* Copyright 2019-2020 The MathWorks, Inc.
44
*/
55

66
public class MatlabBuilderConstants {
@@ -16,6 +16,7 @@ public class MatlabBuilderConstants {
1616
static final String AUTOMATIC_OPTION = "RunTestsAutomaticallyOption";
1717

1818
// Input parameter names (Passed to runMatlabTests.m as name-value pair arguments)
19+
static final String PDF_REPORT = "'PDFReport'";
1920
static final String TAP_RESULTS = "'TAPResults'";
2021
static final String JUNIT_RESULTS = "'JUnitResults'";
2122
static final String STM_RESULTS = "'SimulinkTestResults'";

src/main/resources/com/mathworks/ci/MatlabBuilder/RunTestsAutomaticallyOption/config.jelly

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
33

44
<f:section title="Generate Test Artifacts">
5+
<f:entry field="taPDFReportChkBx">
6+
<f:checkbox title="PDF test report " name="taPDFReportChkBx" checked="${instance.taPDFReportChkBx}"/>
7+
</f:entry>
8+
59
<f:entry field="tatapChkBx">
610
<f:checkbox title="TAP test results" name="tatapChkBx" checked="${instance.tatapChkBx}"/>
711
</f:entry>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<div>
22
<br>
33
Generate a test report in PDF format, <b>testreport.pdf</b>, and save it in the <b>matlabTestArtifacts</b> folder of the Jenkins workspace.
4-
<br>
5-
<br>
6-
Note: Due to Jenkins Content Security Policy rules, the generated report might not open properly from within the Jenkins workspace.
4+
<br><br>
5+
Due to Jenkins Content Security Policy rules, the generated report might not open properly from within the Jenkins workspace.
76
Consider copying the report to a location outside the workspace and opening it from there. For more information,
87
see <a href="http://wiki.jenkins.io/display/JENKINS/Configuring+Content+Security+Policy">Configuring Jenkins Content Security Policy</a>.
9-
<br>
8+
<br><br>
9+
<b>Note:</b>This feature is not currently supported on MacOS platforms.
1010
</div>

src/main/resources/com/mathworks/ci/MatlabBuilder/runMatlabTests.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
%Copyright 2019 The MathWorks, Inc.
1+
%Copyright 2019-2020 The MathWorks, Inc.
22

33
function failed = runMatlabTests(varargin)
44

@@ -73,7 +73,7 @@
7373
BASE_VERSION_COBERTURA_SUPPORT = '9.3';
7474

7575
if verLessThan('matlab',BASE_VERSION_COBERTURA_SUPPORT)
76-
warning('MATLAB:testArtifact:coberturaReportNotSupported', 'Producing Cobertura results is not supported in this release.');
76+
warning('MATLAB:testArtifact:coberturaReportNotSupported', 'Producing Cobertura code coverage results is not supported in this release.');
7777
else
7878
import('matlab.unittest.plugins.CodeCoveragePlugin');
7979
mkdirIfNeeded(resultsDir)
@@ -111,9 +111,12 @@
111111
end
112112
end
113113

114-
% Produce PDF test report (Not supported below R2016b)
114+
% Produce PDF test report (Not supported on MacOS platforms and below R2017a)
115115
if producePDFReport
116-
if ~testReportPluginPresent
116+
if ismac
117+
warning('MATLAB:testArtifact:unSupportedPlatform', ...
118+
'Producing a PDF test report is not currently supported on MacOS platforms.');
119+
elseif ~testReportPluginPresent
117120
issuePDFReportUnsupportedWarning;
118121
else
119122
mkdirIfNeeded(resultsDir);
@@ -129,6 +132,7 @@
129132
results = runner.run(suite);
130133
failed = any([results.Failed]);
131134

135+
132136
function tapToFile = getTapResultFile(resultsDir)
133137
import('matlab.unittest.plugins.ToFile');
134138
mkdirIfNeeded(resultsDir)
@@ -164,7 +168,7 @@ function mkdirIfNeeded(dir)
164168
filePath = fullfile(resultsDir, 'simulinktestresults.mldatx');
165169

166170
function tf = testReportPluginPresent
167-
BASE_VERSION_REPORTPLUGIN_SUPPORT = '9.1'; % R2016b
171+
BASE_VERSION_REPORTPLUGIN_SUPPORT = '9.2'; % R2017a
168172

169173
tf = ~verLessThan('matlab',BASE_VERSION_REPORTPLUGIN_SUPPORT);
170174

src/test/java/com/mathworks/ci/MatlabBuilderTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333

3434
/*
35-
* Copyright 2018-2019 The MathWorks, Inc.
35+
* Copyright 2018-2020 The MathWorks, Inc.
3636
*
3737
* Test class for MatlabBuilder
3838
*
@@ -300,7 +300,7 @@ public void verifyRunTestAutomaticallyIsDefault() throws Exception {
300300
this.matlabBuilder.setMatlabRoot(getMatlabroot("R2018b"));
301301
FreeStyleBuild build = getBuildforRunTestAutomatically();
302302
jenkins.assertLogContains("-batch", build);
303-
jenkins.assertLogContains("\'TAPResults\',true," +
303+
jenkins.assertLogContains("\'PDFReport\',true,\'TAPResults\',true," +
304304
"\'JUnitResults\',true,\'SimulinkTestResults\',true," +
305305
"\'CoberturaCodeCoverage\',true,\'CoberturaModelCoverage\',true", build);
306306
}
@@ -572,6 +572,7 @@ private FreeStyleBuild getBuildforRunTestAutomatically() throws InterruptedExcep
572572
runOption.setTatapChkBx(true);
573573
runOption.setTaModelCoverageChkBx(true);
574574
runOption.setTaSTMResultsChkBx(true);
575+
runOption.setTaPDFReportChkBx(true);
575576
this.matlabBuilder.setTestRunTypeList(runOption);
576577
project.getBuildersList().add(this.matlabBuilder);
577578
FreeStyleBuild build = project.scheduleBuild2(0).get();

0 commit comments

Comments
 (0)