Skip to content

Commit 2eaf669

Browse files
New Azure Test plan task (#19440)
* created new PR * updated package.json * updating packages file * updated commit with retrieval logic * rebuilt local * updated api call method name * added sample command and removed sleep statement * updated icon * updated task description * updated logic for selecting tests * Updated error message * added null check * removed -v from python invoker * updated resources file * updated task fail logic * updated task fail condition * updated task name * updated * updated deleted files * added utils file * added constants file and console.error * added public doc link * added task failre on api failure * updated if condition * updated error scenario * review comments update * updated indentation * added null checks
1 parent 5e0b1b9 commit 2eaf669

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+4419
-1
lines changed

.github/CODEOWNERS

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ Tasks/AzureSpringCloudV0 @microsoft/azure-spring-apps @ruoyuwang @menxiao
9090

9191
Tasks/AzureStaticWebAppV0/ @microsoft/azure-static-web-apps @mkarmark @joslinmicrosoft
9292

93+
Tasks/AzureTestPlanV0/ @rasunkar @microsoft\adoautotest
94+
9395
Tasks/AzureWebAppV1/ @vsebesta @rvairavelu @pipeline-environment-team
9496

9597
Tasks/AzureWebAppContainerV1/ @vsebesta @rvairavelu @pipeline-environment-team
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { spawn } from '../testexecutor'
2+
import tl = require('azure-pipelines-task-lib/task');
3+
import utils = require('../utils');
4+
import constants = require('../constants');
5+
export async function executegradletests(testsToBeExecuted: string[]) {
6+
7+
//public doc link: https://docs.gradle.org/current/userguide/command_line_interface.html
8+
//gradle command like "gradle test --tests=<package.className.testName> --tests=<package.className.testName>"
9+
10+
const executable = constants.GRADLE_EXECUTABLE;
11+
const args = []
12+
13+
args.push('test');
14+
15+
for (let testcase of testsToBeExecuted) {
16+
17+
// in some cases found that gradle is including () in test name
18+
utils.removeParenthesesFromEnd(testcase);
19+
args.push('--tests=' + testcase);
20+
}
21+
22+
tl.debug("Executing gradle tests with executable : " + executable);
23+
tl.debug("Executing gradle tests with args :" + args);
24+
25+
const { status, error } = await spawn(executable, args)
26+
if (error) {
27+
tl.error("Error executing gradle command, " + error);
28+
}
29+
30+
return { exitCode: status ?? 1 }
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { spawn } from '../testexecutor'
2+
import tl = require('azure-pipelines-task-lib/task');
3+
import utils = require('../utils');
4+
import constants = require('../constants');
5+
6+
export async function executemaventests(testsToBeExecuted: string[]) {
7+
8+
//public doc link: https://maven.apache.org/surefire/maven-surefire-plugin/examples/single-test.html
9+
//maven command like "mvn test -Dtest=<package.className#testName>,<package.className#testName1>"
10+
11+
const executable = constants.MVN_EXECUTABLE;
12+
const args = []
13+
const testsToRun =[]
14+
15+
for (let tests of testsToBeExecuted) {
16+
const modifiedTest = utils.replaceLastDotWithHash(tests);
17+
testsToRun.push(modifiedTest);
18+
}
19+
20+
if (testsToRun.length > 0)
21+
{
22+
const testsList = testsToRun.join(',')
23+
const dtest = constants.MAVEN_DTEST;
24+
const combinedTestArgs = dtest + testsList;
25+
26+
args.push('test');
27+
args.push(combinedTestArgs);
28+
}
29+
30+
tl.debug("Executing java maven tests with executable : " + executable);
31+
tl.debug("Executing java maven tests with args :" + args);
32+
33+
const { status, error } = await spawn(executable, args)
34+
if (error) {
35+
tl.error("Error executing mvn command, " + error);
36+
}
37+
38+
return { exitCode: status ?? 1 }
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { spawn } from '../testexecutor'
2+
import tl = require('azure-pipelines-task-lib/task');
3+
import constants = require('../constants');
4+
5+
export async function executepythontests(testsToBeExecuted: string[]) {
6+
7+
//public doc link: https://docs.pytest.org/en/7.1.x/how-to/usage.html#specifying-which-tests-to-run
8+
//pytest command like "pytest -v <package.className.testName1> <package.className.testName2> --junitxml=junit.xml"
9+
10+
const executable = constants.PYTEST_EXECUTABLE;
11+
let args: string[] = [];
12+
13+
for (let testcase of testsToBeExecuted) {
14+
args.push(testcase);
15+
}
16+
17+
args.push('--junitxml=junit.xml')
18+
19+
tl.debug("Executing python tests with executable : " + executable);
20+
tl.debug("Executing python tests with args :" + args);
21+
22+
const { status, error } = await spawn(executable, args)
23+
24+
if (error) {
25+
tl.error("Error executing pytest command, " + error);
26+
}
27+
28+
return { exitCode: status ?? 1 }
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"loc.friendlyName": "Azure Test Plan",
3+
"loc.helpMarkDown": "[Learn more about this task](https://go.microsoft.com/fwlink/?LinkID=613742)",
4+
"loc.description": "Run manual and automated tests in test plan in Java and python language",
5+
"loc.instanceNameFormat": "Azure Test Plan - $(testSelector)",
6+
"loc.input.label.testSelector": "Test cases to be executed",
7+
"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.testPlan": "Test plan",
9+
"loc.input.help.testPlan": "Select a test plan containing test suites with test cases.",
10+
"loc.input.label.testSuite": "Test suite",
11+
"loc.input.help.testSuite": "Select one or more test suites containing test cases.",
12+
"loc.input.label.testConfiguration": "Test configuration",
13+
"loc.input.help.testConfiguration": "Select Test Configuration.",
14+
"loc.input.label.testLanguageInput": "Select Test framework language",
15+
"loc.input.help.testLanguageInput": "Test Framework Language of automated tests in test plan",
16+
"loc.messages.testPlanInput": "Test plan Id : %s",
17+
"loc.messages.testplanConfigInput": "Test plan configuration Id : %s",
18+
"loc.messages.testSuiteSelected": "Test suite Id selected: %s",
19+
"loc.messages.automatedTestsTriggered": "Trigerring execution of Automated tests from test plan",
20+
"loc.messages.ErrorFailTaskOnExecutingTests": "Error occured while executing test command",
21+
"loc.messages.ErrorFailTaskOnAPIFailure": "Error occured while fetching automated tests from test plan inputs"
22+
}

0 commit comments

Comments
 (0)