Skip to content

Commit b96a66d

Browse files
authored
Run ATP from Test Plans - Run with Options to execute custom selected test cases (#20887)
* add test run in input. * start using test api to retrieve test cases using testRunId. * methods created. * tests getting populated. * manual test detection. * type safety. * nit. * fix run issue * version * switched to console log * Revert "switched to console log" This reverts commit d2e7493. * api endpoint.
1 parent 62f57ea commit b96a66d

File tree

7 files changed

+222
-110
lines changed

7 files changed

+222
-110
lines changed

Tasks/AzureTestPlanV0/Automated Flow/automatedFlow.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ async function publishResults(
109109
}
110110

111111
await publishAutomatedTestResult(
112-
JSON.stringify(testPlanInfo.listOfAutomatedTestPoints)
112+
JSON.stringify(testPlanInfo.listOfAutomatedTestPoints),
113+
testPlanInfo.listOfAutomatedTestPoints.length ? testPlanInfo.listOfAutomatedTestPoints[0].testPlan?.id : ""
113114
);
114115
return createSuccessResult();
115116

Tasks/AzureTestPlanV0/Common/publishAutomatedTests.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import tl = require('azure-pipelines-task-lib/task');
22
import * as path from 'path';
33
import constants = require('./constants');
44

5-
function publish(testRunner, resultFiles, mergeResults, failTaskOnFailedTests, platform, publishRunAttachments, testRunSystem , failTaskOnFailureToPublishResults, listOfAutomatedTestPoints) {
5+
function publish(testRunner, resultFiles, mergeResults, failTaskOnFailedTests, platform, publishRunAttachments, testRunSystem , failTaskOnFailureToPublishResults, listOfAutomatedTestPoints, testPlan) {
66
var properties = <{ [key: string]: string }>{};
77
properties['type'] = testRunner;
88
properties['mergeResults'] = mergeResults;
@@ -14,14 +14,14 @@ function publish(testRunner, resultFiles, mergeResults, failTaskOnFailedTests, p
1414
properties['testRunSystem'] = testRunSystem;
1515
properties['listOfAutomatedTestPoints'] = listOfAutomatedTestPoints;
1616

17-
var testPlanId = tl.getInput('testPlan');
17+
var testPlanId = testPlan ?? tl.getInput('testPlan');
1818
tl.debug('testPlanId: ' + testPlanId);
1919
properties['testPlanId'] = testPlanId;
2020

2121
tl.command('results.publish', properties, '');
2222
}
2323

24-
export async function publishAutomatedTestResult(listOfAutomatedTestPoints: string) {
24+
export async function publishAutomatedTestResult(listOfAutomatedTestPoints: string, testPlan: string) {
2525
try{
2626
const testRunner = "JUnit";
2727
const testResultsFiles: string[] = ["**/TEST-*.xml"];
@@ -81,7 +81,8 @@ export async function publishAutomatedTestResult(listOfAutomatedTestPoints: stri
8181
publishRunAttachments,
8282
testRunSystem,
8383
failTaskOnFailureToPublishResults,
84-
listOfAutomatedTestPoints);
84+
listOfAutomatedTestPoints,
85+
testPlan);
8586
}
8687
} catch (err) {
8788
throw new Error('Faced error while publishing test results:' + err.message);

Tasks/AzureTestPlanV0/OldAutomatedFlow/automatedTests.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async function publishResults(testPlanInfo: TestPlanData, ciData: ciDictionary,
4949
publishingTimer.start();
5050

5151
try {
52-
await publishAutomatedTestResult(JSON.stringify(testPlanInfo.listOfAutomatedTestPoints));
52+
await publishAutomatedTestResult(JSON.stringify(testPlanInfo.listOfAutomatedTestPoints), testPlanInfo.listOfAutomatedTestPoints.length ? testPlanInfo.listOfAutomatedTestPoints[0].testPlan?.id : "");
5353
} catch (err) {
5454
automatedTestInvokerResult.returnCode = 1;
5555
automatedTestInvokerResult.errorMessage = err.message || String(err);

Tasks/AzureTestPlanV0/Strings/resources.resjson/en-US/resources.resjson

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
"loc.instanceNameFormat": "Azure Test Plan - $(testSelector)",
66
"loc.input.label.testSelector": "Test cases to be executed",
77
"loc.input.help.testSelector": "<ul><li><b>Manual tests: </b>Use this option to trigger manual tests from your test plan.</li><li><b>Automated tests: </b>Use this option to run tests from your test plan that have automated test method associated with it.</li>",
8+
"loc.input.label.testPlanOrRunSelector": "Select tests using",
9+
"loc.input.help.testPlanOrRunSelector": "<ul><li><b>Test assembly: </b>Use this option to specify one or more test assemblies that contain your tests. You can optionally specify a filter criteria to select only specific tests.</li><li><b>Test plan: </b>Use this option to run tests from your test plan that have an automated test method associated with it.</li><li><b>Test run: </b>Use this option when you are setting up an environment to run tests from the Test hub. This option should not be used when running tests in a continuous integration / continuous deployment (CI/CD) pipeline.</li>",
10+
"loc.input.label.testRunId": "Test Run",
11+
"loc.input.help.testRunId": "Test run based selection is used when triggering automated test runs from the test hub, value for this should be kept as it is",
812
"loc.input.label.testPlan": "Test plan",
913
"loc.input.help.testPlan": "Type or paste the test plan ID containing test suites with test cases.",
1014
"loc.input.label.testSuite": "Test suite",

Tasks/AzureTestPlanV0/task.json

+30-5
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"author": "Microsoft Corporation",
1414
"version": {
1515
"Major": 0,
16-
"Minor": 253,
17-
"Patch": 8
16+
"Minor": 254,
17+
"Patch": 1
1818
},
1919
"preview": true,
2020
"demands": [],
@@ -34,6 +34,30 @@
3434
"MultiSelectFlatList": "True"
3535
}
3636
},
37+
{
38+
"name": "testPlanOrRunSelector",
39+
"type": "pickList",
40+
"label": "Select tests using",
41+
"defaultValue": "testPlan",
42+
"required": true,
43+
"helpMarkDown": "<ul><li><b>Test assembly: </b>Use this option to specify one or more test assemblies that contain your tests. You can optionally specify a filter criteria to select only specific tests.</li><li><b>Test plan: </b>Use this option to run tests from your test plan that have an automated test method associated with it.</li><li><b>Test run: </b>Use this option when you are setting up an environment to run tests from the Test hub. This option should not be used when running tests in a continuous integration / continuous deployment (CI/CD) pipeline.</li>",
44+
"options": {
45+
"testPlan": "Test plan",
46+
"testRun": "Test run"
47+
},
48+
"properties": {
49+
"EditableOptions": "True"
50+
}
51+
},
52+
{
53+
"name": "testRunId",
54+
"type": "string",
55+
"label": "Test Run",
56+
"defaultValue": "$(test.RunId)",
57+
"required": true,
58+
"helpMarkDown": "Test run based selection is used when triggering automated test runs from the test hub, value for this should be kept as it is",
59+
"visibleRule": "testPlanOrRunSelector = testRun"
60+
},
3761
{
3862
"name": "testPlan",
3963
"type": "string",
@@ -44,7 +68,8 @@
4468
"properties": {
4569
"DisableManageLink": "True",
4670
"EditableOptions": "True"
47-
}
71+
},
72+
"visibleRule": "testPlanOrRunSelector = testPlan"
4873
},
4974
{
5075
"name": "testSuite",
@@ -54,10 +79,10 @@
5479
"helpMarkDown": "Select one or more test suites containing test cases.",
5580
"required": true,
5681
"properties": {
57-
"MultiSelect": "True",
5882
"DisableManageLink": "True",
5983
"EditableOptions": "True"
60-
}
84+
},
85+
"visibleRule": "testPlanOrRunSelector = testPlan"
6186
},
6287
{
6388
"name": "testConfiguration",

Tasks/AzureTestPlanV0/task.loc.json

+30-5
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"author": "Microsoft Corporation",
1414
"version": {
1515
"Major": 0,
16-
"Minor": 253,
17-
"Patch": 8
16+
"Minor": 254,
17+
"Patch": 1
1818
},
1919
"preview": true,
2020
"demands": [],
@@ -34,6 +34,30 @@
3434
"MultiSelectFlatList": "True"
3535
}
3636
},
37+
{
38+
"name": "testPlanOrRunSelector",
39+
"type": "pickList",
40+
"label": "ms-resource:loc.input.label.testPlanOrRunSelector",
41+
"defaultValue": "testPlan",
42+
"required": true,
43+
"helpMarkDown": "ms-resource:loc.input.help.testPlanOrRunSelector",
44+
"options": {
45+
"testPlan": "Test plan",
46+
"testRun": "Test run"
47+
},
48+
"properties": {
49+
"EditableOptions": "True"
50+
}
51+
},
52+
{
53+
"name": "testRunId",
54+
"type": "string",
55+
"label": "ms-resource:loc.input.label.testRunId",
56+
"defaultValue": "$(test.RunId)",
57+
"required": true,
58+
"helpMarkDown": "ms-resource:loc.input.help.testRunId",
59+
"visibleRule": "testPlanOrRunSelector = testRun"
60+
},
3761
{
3862
"name": "testPlan",
3963
"type": "string",
@@ -44,7 +68,8 @@
4468
"properties": {
4569
"DisableManageLink": "True",
4670
"EditableOptions": "True"
47-
}
71+
},
72+
"visibleRule": "testPlanOrRunSelector = testPlan"
4873
},
4974
{
5075
"name": "testSuite",
@@ -54,10 +79,10 @@
5479
"helpMarkDown": "ms-resource:loc.input.help.testSuite",
5580
"required": true,
5681
"properties": {
57-
"MultiSelect": "True",
5882
"DisableManageLink": "True",
5983
"EditableOptions": "True"
60-
}
84+
},
85+
"visibleRule": "testPlanOrRunSelector = testPlan"
6186
},
6287
{
6388
"name": "testConfiguration",

0 commit comments

Comments
 (0)