Skip to content

Commit

Permalink
New Azure Test plan task (#19440)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
triptijain2112 committed Jan 23, 2024
1 parent 5e0b1b9 commit 2eaf669
Show file tree
Hide file tree
Showing 45 changed files with 4,419 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ Tasks/AzureSpringCloudV0 @microsoft/azure-spring-apps @ruoyuwang @menxiao

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

Tasks/AzureTestPlanV0/ @rasunkar @microsoft\adoautotest

Tasks/AzureWebAppV1/ @vsebesta @rvairavelu @pipeline-environment-team

Tasks/AzureWebAppContainerV1/ @vsebesta @rvairavelu @pipeline-environment-team
Expand Down
31 changes: 31 additions & 0 deletions Tasks/AzureTestPlanV0/Invokers/gradleinvoker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { spawn } from '../testexecutor'
import tl = require('azure-pipelines-task-lib/task');
import utils = require('../utils');
import constants = require('../constants');
export async function executegradletests(testsToBeExecuted: string[]) {

//public doc link: https://docs.gradle.org/current/userguide/command_line_interface.html
//gradle command like "gradle test --tests=<package.className.testName> --tests=<package.className.testName>"

const executable = constants.GRADLE_EXECUTABLE;
const args = []

args.push('test');

for (let testcase of testsToBeExecuted) {

// in some cases found that gradle is including () in test name
utils.removeParenthesesFromEnd(testcase);
args.push('--tests=' + testcase);
}

tl.debug("Executing gradle tests with executable : " + executable);
tl.debug("Executing gradle tests with args :" + args);

const { status, error } = await spawn(executable, args)
if (error) {
tl.error("Error executing gradle command, " + error);
}

return { exitCode: status ?? 1 }
}
39 changes: 39 additions & 0 deletions Tasks/AzureTestPlanV0/Invokers/maveninvoker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { spawn } from '../testexecutor'
import tl = require('azure-pipelines-task-lib/task');
import utils = require('../utils');
import constants = require('../constants');

export async function executemaventests(testsToBeExecuted: string[]) {

//public doc link: https://maven.apache.org/surefire/maven-surefire-plugin/examples/single-test.html
//maven command like "mvn test -Dtest=<package.className#testName>,<package.className#testName1>"

const executable = constants.MVN_EXECUTABLE;
const args = []
const testsToRun =[]

for (let tests of testsToBeExecuted) {
const modifiedTest = utils.replaceLastDotWithHash(tests);
testsToRun.push(modifiedTest);
}

if (testsToRun.length > 0)
{
const testsList = testsToRun.join(',')
const dtest = constants.MAVEN_DTEST;
const combinedTestArgs = dtest + testsList;

args.push('test');
args.push(combinedTestArgs);
}

tl.debug("Executing java maven tests with executable : " + executable);
tl.debug("Executing java maven tests with args :" + args);

const { status, error } = await spawn(executable, args)
if (error) {
tl.error("Error executing mvn command, " + error);
}

return { exitCode: status ?? 1 }
}
29 changes: 29 additions & 0 deletions Tasks/AzureTestPlanV0/Invokers/pythonivoker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { spawn } from '../testexecutor'
import tl = require('azure-pipelines-task-lib/task');
import constants = require('../constants');

export async function executepythontests(testsToBeExecuted: string[]) {

//public doc link: https://docs.pytest.org/en/7.1.x/how-to/usage.html#specifying-which-tests-to-run
//pytest command like "pytest -v <package.className.testName1> <package.className.testName2> --junitxml=junit.xml"

const executable = constants.PYTEST_EXECUTABLE;
let args: string[] = [];

for (let testcase of testsToBeExecuted) {
args.push(testcase);
}

args.push('--junitxml=junit.xml')

tl.debug("Executing python tests with executable : " + executable);
tl.debug("Executing python tests with args :" + args);

const { status, error } = await spawn(executable, args)

if (error) {
tl.error("Error executing pytest command, " + error);
}

return { exitCode: status ?? 1 }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"loc.friendlyName": "Azure Test Plan",
"loc.helpMarkDown": "[Learn more about this task](https://go.microsoft.com/fwlink/?LinkID=613742)",
"loc.description": "Run manual and automated tests in test plan in Java and python language",
"loc.instanceNameFormat": "Azure Test Plan - $(testSelector)",
"loc.input.label.testSelector": "Test cases to be executed",
"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>",
"loc.input.label.testPlan": "Test plan",
"loc.input.help.testPlan": "Select a test plan containing test suites with test cases.",
"loc.input.label.testSuite": "Test suite",
"loc.input.help.testSuite": "Select one or more test suites containing test cases.",
"loc.input.label.testConfiguration": "Test configuration",
"loc.input.help.testConfiguration": "Select Test Configuration.",
"loc.input.label.testLanguageInput": "Select Test framework language",
"loc.input.help.testLanguageInput": "Test Framework Language of automated tests in test plan",
"loc.messages.testPlanInput": "Test plan Id : %s",
"loc.messages.testplanConfigInput": "Test plan configuration Id : %s",
"loc.messages.testSuiteSelected": "Test suite Id selected: %s",
"loc.messages.automatedTestsTriggered": "Trigerring execution of Automated tests from test plan",
"loc.messages.ErrorFailTaskOnExecutingTests": "Error occured while executing test command",
"loc.messages.ErrorFailTaskOnAPIFailure": "Error occured while fetching automated tests from test plan inputs"
}
Loading

0 comments on commit 2eaf669

Please sign in to comment.