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

Commit 7b313a7

Browse files
authored
Merge pull request #166 from mathworks/filter_tests
Filter tests using selectByFolder & selectByTag
2 parents dbb226c + 453246b commit 7b313a7

File tree

5 files changed

+72
-4
lines changed

5 files changed

+72
-4
lines changed

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

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ public class RunMatlabTestsStep extends Step {
3232
private String codeCoverageCobertura;
3333
private String testResultsSimulinkTest;
3434
private String modelCoverageCobertura;
35+
private String selectByTag;
3536
private List<String> sourceFolder = new ArrayList<>();
37+
private List<String> selectByFolder = new ArrayList<>();
3638

3739
@DataBoundConstructor
3840
public RunMatlabTestsStep() {
@@ -102,6 +104,24 @@ public List<String> getSourceFolder() {
102104
public void setSourceFolder(List<String> sourceFolder) {
103105
this.sourceFolder = Util.fixNull(sourceFolder);
104106
}
107+
108+
public String getSelectByTag() {
109+
return this.selectByTag;
110+
}
111+
112+
@DataBoundSetter
113+
public void setSelectByTag(String selectByTag) {
114+
this.selectByTag = selectByTag;
115+
}
116+
117+
public List<String> getSelectByFolder() {
118+
return this.selectByFolder;
119+
}
120+
121+
@DataBoundSetter
122+
public void setSelectByFolder(List<String> selectByFolder) {
123+
this.selectByFolder = selectByFolder;
124+
}
105125

106126
@Override
107127
public StepExecution start(StepContext context) throws Exception {
@@ -135,7 +155,7 @@ private String getInputArgs() {
135155
inputArgs.add("'Test'");
136156

137157
args.forEach((key, val) -> {
138-
if(key.equals("SourceFolder") && val != null){
158+
if(key.equals("SourceFolder") || key.equals("SelectByFolder") && val != null){
139159
inputArgs.add("'" + key + "'" + "," + val);
140160
}else if(val != null){
141161
inputArgs.add("'" + key + "'" + "," + "'" + val.replaceAll("'", "''") + "'");
@@ -153,9 +173,15 @@ private Map<String, String> getGenscriptArgs() {
153173
args.put("SimulinkTestResults", getTestResultsSimulinkTest());
154174
args.put("CoberturaCodeCoverage", getCodeCoverageCobertura());
155175
args.put("CoberturaModelCoverage", getModelCoverageCobertura());
156-
if(!getSourceFolder().isEmpty()){
157-
args.put("SourceFolder", Utilities.getCellArrayFrmList(getSourceFolder()));
158-
}
176+
args.put("SelectByTag", getSelectByTag());
177+
addFolderArgs("SourceFolder",getSourceFolder(),args);
178+
addFolderArgs("SelectByFolder",getSelectByFolder(),args);
159179
return args;
160180
}
181+
182+
private void addFolderArgs(String argName,List<String> value,Map<String,String> args) {
183+
if(!value.isEmpty()){
184+
args.put(argName, Utilities.getCellArrayFrmList(value));
185+
}
186+
}
161187
}

src/main/resources/com/mathworks/ci/RunMatlabTestsStep/config.jelly

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?jelly escape-by-default='true'?>
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

4+
45
<f:entry field="testResultsPDF" title="testResultsPDF: ">
56
<f:textbox/>
67
</f:entry>
@@ -24,6 +25,14 @@
2425
<f:entry field="modelCoverageCobertura" title="modelCoverageCobertura: ">
2526
<f:textbox/>
2627
</f:entry>
28+
29+
<f:entry field="selectByFolder" title="selectByFolder: ">
30+
<f:textbox/>
31+
</f:entry>
32+
33+
<f:entry field="selectByTag" title="selectByTag: ">
34+
<f:textbox/>
35+
</f:entry>
2736

2837
<f:entry field="sourceFolder" title="sourceFolder: ">
2938
<f:textbox/>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div>
2+
<p>Specify the locations of folders containing tests, relative to the project root folder, as a list of strings. To generate a test suite, MATLAB uses only the tests in the specified folders and their subfolders.</p>
3+
<p><b>Example:</b> ["test/folderA", "test/folderB"]</p>
4+
</div>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div>
2+
<p>Specify the test tag used to select test suite elements. To generate a test suite, MATLAB uses only the test elements with the specified tag.</p>
3+
<p><b>Example:</b> 'FeatureA'</p>
4+
</div>

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,29 @@ public void verifyEmptyParameter() throws Exception {
125125
j.assertLogNotContains("SimulinkTestResultsPath", build);
126126
j.assertLogNotContains("CoberturaModelCoveragePath", build);
127127
}
128+
129+
/*@Integ Test
130+
* Verify default command options for test Filter using selectByFolder option
131+
*/
132+
133+
public void verifyTestSelectByFolder () throws Exception {
134+
project.setDefinition(new CpsFlowDefinition(
135+
"node {runMATLABTests(selectByFolder:['mytest1','mytest2'])}", true));
136+
WorkflowRun build = project.scheduleBuild2(0).get();
137+
j.assertLogContains("mytest1", build);
138+
j.assertLogContains("mytest2", build);
139+
j.assertBuildStatusSuccess(build);
140+
}
141+
142+
/*@Integ Test
143+
* Verify default command options for test Filter using selectByTag option
144+
*/
145+
146+
public void verifyTestSelectByTag () throws Exception {
147+
project.setDefinition(new CpsFlowDefinition(
148+
"node {runMATLABTests(selectByTag: 'myTestTag')}", true));
149+
WorkflowRun build = project.scheduleBuild2(0).get();
150+
j.assertLogContains("myTestTag", build);
151+
j.assertBuildStatusSuccess(build);
152+
}
128153
}

0 commit comments

Comments
 (0)