Skip to content

Commit 649e9ca

Browse files
authored
Adding tests for ATP (#20907)
* adding tests for ATP * npmrc and naming * fixing registry error. * fix registry. * version. * registry
1 parent 2993143 commit 649e9ca

File tree

9 files changed

+444
-2
lines changed

9 files changed

+444
-2
lines changed

Tasks/AzureTestPlanV0/Tests/.npmrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
registry=https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/
2+
3+
always-auth=true

Tasks/AzureTestPlanV0/Tests/L0.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import fs = require('fs');
2+
import assert = require('assert');
3+
import path = require('path');
4+
import ttm = require('azure-pipelines-task-lib/mock-test');
5+
const tl = require('azure-pipelines-task-lib/task');
6+
import { TestPlanData } from '../testPlanData';
7+
import { newAutomatedTestsFlow } from '../Automated Flow/automatedFlow';
8+
9+
describe('AzureTestPlan Suite', function () {
10+
this.timeout(10000);
11+
12+
const originalGetInput = tl.getInput;
13+
const originalGetBoolInput = tl.getBoolInput;
14+
15+
beforeEach(() => {
16+
tl.getInput = (key, required) => key === 'testLanguageInput' ? 'Python' : null;
17+
tl.getBoolInput = () => false;
18+
});
19+
20+
afterEach(() => {
21+
tl.getInput = originalGetInput;
22+
tl.getBoolInput = originalGetBoolInput;
23+
});
24+
25+
it('Check if runs fine', (done: Mocha.Done) => {
26+
this.timeout(1000);
27+
28+
let tp: string = path.join(__dirname, 'L0SampleTest.js');
29+
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
30+
31+
tr.runAsync().then(() => {
32+
assert(tr.stdOutContained(`Test Selector selected`),
33+
`Should have looked Test Selector`);
34+
35+
assert(tr.stdOutContained(`Test Plan Id:`),
36+
`Should have looked for Test Plan Id`);
37+
38+
assert(tr.stdOutContained(`Test Plan Configuration Id:`),
39+
`Should have looked for Test Plan Configuration Id`);
40+
41+
assert(tr.stdOutContained(`Test Suite Ids:`),
42+
`Should have looked for Test Suite Ids`);
43+
44+
done();
45+
}).catch((err) => {
46+
console.error('Test run failed:', err);
47+
throw err;
48+
});
49+
});
50+
51+
it('should return error when testLanguageInput is missing', async function () {
52+
tl.getInput = () => null;
53+
const testPlanInfo = { listOfFQNOfTestCases: [] } as TestPlanData;
54+
const result = await newAutomatedTestsFlow(testPlanInfo, 'someSelector', {});
55+
assert.strictEqual(result.returnCode, 1);
56+
assert.strictEqual(result.errorMessage, 'Test language input is required');
57+
});
58+
59+
it('should return error when no tests are found in test plan', async function () {
60+
const testPlanInfo = { listOfFQNOfTestCases: [] } as TestPlanData;
61+
testPlanInfo.listOfFQNOfTestCases = [];
62+
const result = await newAutomatedTestsFlow(testPlanInfo, 'automatedTests', {});
63+
assert.strictEqual(result.returnCode, 1);
64+
});
65+
66+
it('should return error if no executor is found for the test language', async function () {
67+
tl.getInput = () => 'unknown-language';
68+
const testPlanInfo = { listOfFQNOfTestCases: [] } as TestPlanData;
69+
testPlanInfo.listOfFQNOfTestCases = ['test1', 'test2'];
70+
const result = await newAutomatedTestsFlow(testPlanInfo, 'someSelector', {});
71+
assert.strictEqual(result.returnCode, 1);
72+
assert.strictEqual(result.errorMessage, 'Test executor not found for test language: unknown-language');
73+
});
74+
75+
it('should handle no automated tests found', async function () {
76+
const testPlanInfo = { listOfFQNOfTestCases: [] } as TestPlanData;
77+
const result = await newAutomatedTestsFlow(testPlanInfo, 'automatedTests', {});
78+
assert.strictEqual(result.returnCode, 1);
79+
assert.strictEqual(result.errorMessage, 'ErrorFailTaskOnNoAutomatedTestsFound');
80+
});
81+
82+
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import ma = require('azure-pipelines-task-lib/mock-answer');
2+
import tmrm = require('azure-pipelines-task-lib/mock-run');
3+
import path = require('path');
4+
import { ExcludeFlags } from 'azure-devops-node-api/interfaces/TestPlanInterfaces';
5+
import { RunCreateModel } from 'azure-devops-node-api/interfaces/TestInterfaces';
6+
import { getTestCaseListResponseWithManualTestPointsOnly, addTestResultsToTestRunResponse, createTestRunResponse } from './SampleApiResponse';
7+
import { setEnvVariables } from './TestSetup';
8+
9+
let taskPath = path.join(__dirname, '..', 'runTestPlan.js');
10+
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
11+
12+
setEnvVariables();
13+
14+
tr.setInput('testPlan', '1');
15+
tr.setInput('testConfiguration', '10');
16+
tr.setInput('testSuite', '2');
17+
tr.setInput('testSelector', 'manualTests');
18+
19+
20+
const tl = require('azure-pipelines-task-lib/mock-task');
21+
const tlClone = Object.assign({}, tl);
22+
23+
tlClone.getEndpointAuthorizationParameter = function () {
24+
return 'ad4sldkajdsf4ksa5randomaccesstoken7lf9adsnfandfjlsdf';
25+
}
26+
tr.registerMock('azure-pipelines-task-lib/mock-task', tlClone);
27+
28+
tr.registerMock('azure-devops-node-api', {
29+
getPersonalAccessTokenHandler: function (token) {
30+
return {};
31+
},
32+
WebApi: function (url, handler) {
33+
return {
34+
getTestPlanApi: function () {
35+
return {
36+
getTestCaseList: function (project: string, planId: number, suiteId: number, testIds?: string, configurationIds?: string, witFields?: string, continuationToken?: string, returnIdentityRef?: boolean, expand?: boolean, excludeFlags?: ExcludeFlags, isRecursive?: boolean) {
37+
return getTestCaseListResponseWithManualTestPointsOnly;
38+
}
39+
};
40+
},
41+
getTestResultsApi: function () {
42+
return {
43+
createTestRun: function (testRun: RunCreateModel, project: string) {
44+
return createTestRunResponse;
45+
},
46+
addTestResultsToTestRun: function (results: any, project: string, runId: number) {
47+
return addTestResultsToTestRunResponse;
48+
}
49+
}
50+
}
51+
};
52+
}
53+
})
54+
55+
tr.run();
Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
import { TestCaseResult, TestRun } from "azure-devops-node-api/interfaces/TestInterfaces";
2+
3+
export const getTestCaseListResponseWithManualTestPointsOnly = [
4+
{
5+
"testPlan": {
6+
"id": 7,
7+
"name": "Test Plan For Delete Functionality"
8+
},
9+
"project": {
10+
"id": "f9ba3132-23a9-49b2-b6b9-55a14a0fdc6f",
11+
"name": "Java Maven",
12+
"state": "unchanged",
13+
"visibility": 0,
14+
"lastUpdateTime": "0000-12-31T18:06:32.000Z"
15+
},
16+
"testSuite": {
17+
"id": 8,
18+
"name": "Test Plan For Delete Functionality"
19+
},
20+
"workItem": {
21+
"id": 9,
22+
"name": "TC1WithAssociationToDelete",
23+
"workItemFields": [
24+
{
25+
"Microsoft.VSTS.Common.ActivatedBy": "Aditya Shah <[email protected]>"
26+
},
27+
{
28+
"Microsoft.VSTS.Common.ActivatedDate": "2024-03-14T20:32:19.27Z"
29+
},
30+
{
31+
"Microsoft.VSTS.TCM.AutomationStatus": "Not Automated"
32+
},
33+
{
34+
"System.State": "Design"
35+
},
36+
{
37+
"System.AssignedTo": "Aditya Shah <[email protected]>"
38+
},
39+
{
40+
"Microsoft.VSTS.Common.Priority": 2
41+
},
42+
{
43+
"Microsoft.VSTS.Common.StateChangeDate": "2024-03-14T20:32:19.27Z"
44+
},
45+
{
46+
"System.WorkItemType": "Test Case"
47+
},
48+
{
49+
"System.Rev": 1
50+
}
51+
]
52+
},
53+
"pointAssignments": [
54+
{
55+
"id": 5,
56+
"configurationName": "Windows 10",
57+
"tester": {
58+
"displayName": "Aditya Shah",
59+
"url": "https://vssps.codedev.ms/e/adoTpmTenant/_apis/Identities/2622cefd-ccd7-61ac-b577-4a5a723ca9a4",
60+
"_links": {
61+
"avatar": {
62+
"href": "https://codedev.ms/AdityaShah/_apis/GraphProfile/MemberAvatars/aad.MjYyMmNlZmQtY2NkNy03MWFjLWI1NzctNGE1YTcyM2NhOWE0"
63+
}
64+
},
65+
"id": "2622cefd-ccd7-61ac-b577-4a5a723ca9a4",
66+
"uniqueName": "[email protected]",
67+
"imageUrl": "https://codedev.ms/AdityaShah/_apis/GraphProfile/MemberAvatars/aad.MjYyMmNlZmQtY2NkNy03MWFjLWI1NzctNGE1YTcyM2NhOWE0",
68+
"descriptor": "aad.MjYyMmNlZmQtY2NkNy03MWFjLWI1NzctNGE1YTcyM2NhOWE0"
69+
},
70+
"configurationId": 1
71+
}
72+
],
73+
"links": {
74+
"testPoints": {
75+
"href": "https://codedev.ms/AdityaShah/Java%20Maven/_apis/testplan/Plans/7/Suites/8/TestPoint/5"
76+
},
77+
"configuration": {
78+
"href": "https://codedev.ms/AdityaShah/Java%20Maven/_apis/testplan/Configurations/1"
79+
},
80+
"_self": {
81+
"href": "https://codedev.ms/AdityaShah/Java%20Maven/_apis/testplan/Plans/7/Suites/8/TestCase"
82+
},
83+
"sourcePlan": {
84+
"href": "https://codedev.ms/AdityaShah/Java%20Maven/_apis/testplan/Plans/7"
85+
},
86+
"sourceSuite": {
87+
"href": "https://codedev.ms/AdityaShah/Java%20Maven/_apis/testplan/Plans/7/Suites/8"
88+
},
89+
"sourceProject": {
90+
"href": "https://codedev.ms/AdityaShah/_apis/projects/Java%20Maven"
91+
}
92+
}
93+
},
94+
{
95+
"testPlan": {
96+
"id": 7,
97+
"name": "Test Plan For Delete Functionality"
98+
},
99+
"project": {
100+
"id": "f9ba3132-23a9-49b2-b6b9-55a14a0fdc6f",
101+
"name": "Java Maven",
102+
"state": "unchanged",
103+
"visibility": 0,
104+
"lastUpdateTime": "0000-12-31T18:06:32.000Z"
105+
},
106+
"testSuite": {
107+
"id": 8,
108+
"name": "Test Plan For Delete Functionality"
109+
},
110+
"workItem": {
111+
"id": 10,
112+
"name": "TC2WithAssociationToDelete",
113+
"workItemFields": [
114+
{
115+
"Microsoft.VSTS.Common.ActivatedBy": "Aditya Shah <[email protected]>"
116+
},
117+
{
118+
"Microsoft.VSTS.Common.ActivatedDate": "2024-03-14T20:32:32.657Z"
119+
},
120+
{
121+
"System.State": "Design"
122+
},
123+
{
124+
"System.AssignedTo": "Aditya Shah <[email protected]>"
125+
},
126+
{
127+
"Microsoft.VSTS.Common.Priority": 2
128+
},
129+
{
130+
"Microsoft.VSTS.Common.StateChangeDate": "2024-03-14T20:32:32.657Z"
131+
},
132+
{
133+
"System.WorkItemType": "Test Case"
134+
},
135+
{
136+
"System.Rev": 3
137+
},
138+
{
139+
"Microsoft.VSTS.TCM.AutomationStatus": "Not Automated"
140+
}
141+
]
142+
},
143+
"order": 1,
144+
"pointAssignments": [
145+
{
146+
"id": 6,
147+
"configurationName": "Windows 10",
148+
"tester": {
149+
"displayName": "Aditya Shah",
150+
"url": "https://vssps.codedev.ms/e/adoTpmTenant/_apis/Identities/2622cefd-ccd7-61ac-b577-4a5a723ca9a4",
151+
"_links": {
152+
"avatar": {
153+
"href": "https://codedev.ms/AdityaShah/_apis/GraphProfile/MemberAvatars/aad.MjYyMmNlZmQtY2NkNy03MWFjLWI1NzctNGE1YTcyM2NhOWE0"
154+
}
155+
},
156+
"id": "2622cefd-ccd7-61ac-b577-4a5a723ca9a4",
157+
"uniqueName": "[email protected]",
158+
"imageUrl": "https://codedev.ms/AdityaShah/_apis/GraphProfile/MemberAvatars/aad.MjYyMmNlZmQtY2NkNy03MWFjLWI1NzctNGE1YTcyM2NhOWE0",
159+
"descriptor": "aad.MjYyMmNlZmQtY2NkNy03MWFjLWI1NzctNGE1YTcyM2NhOWE0"
160+
},
161+
"configurationId": 1
162+
}
163+
],
164+
"links": {
165+
"testPoints": {
166+
"href": "https://codedev.ms/AdityaShah/Java%20Maven/_apis/testplan/Plans/7/Suites/8/TestPoint/6"
167+
},
168+
"configuration": {
169+
"href": "https://codedev.ms/AdityaShah/Java%20Maven/_apis/testplan/Configurations/1"
170+
},
171+
"_self": {
172+
"href": "https://codedev.ms/AdityaShah/Java%20Maven/_apis/testplan/Plans/7/Suites/8/TestCase"
173+
},
174+
"sourcePlan": {
175+
"href": "https://codedev.ms/AdityaShah/Java%20Maven/_apis/testplan/Plans/7"
176+
},
177+
"sourceSuite": {
178+
"href": "https://codedev.ms/AdityaShah/Java%20Maven/_apis/testplan/Plans/7/Suites/8"
179+
},
180+
"sourceProject": {
181+
"href": "https://codedev.ms/AdityaShah/_apis/projects/Java%20Maven"
182+
}
183+
}
184+
}
185+
];
186+
187+
export const createTestRunResponse: TestRun = {
188+
"id": 174,
189+
"name": "Manual test run",
190+
"url": "https://codedev.ms/AdityaShah/Java%20Maven/_apis/test/Runs/174",
191+
"build": {
192+
"id": "56"
193+
},
194+
"isAutomated": false,
195+
"iteration": "manual",
196+
"owner": {
197+
"displayName": null,
198+
"id": "00000000-0000-0000-0000-000000000000"
199+
},
200+
"project": {
201+
"id": "f9ba3132-23a9-49b2-b6b9-55a14a0fdc6f",
202+
"name": "Java Maven"
203+
},
204+
"state": "Unspecified",
205+
"plan": {
206+
"id": "7"
207+
},
208+
"totalTests": 0,
209+
"incompleteTests": 0,
210+
"notApplicableTests": 0,
211+
"passedTests": 0,
212+
"unanalyzedTests": 0,
213+
"revision": 2,
214+
"webAccessUrl": "https://codedev.ms/AdityaShah/Java%20Maven/_TestManagement/Runs?runId=174&_a=runCharts"
215+
};
216+
217+
export const addTestResultsToTestRunResponse: TestCaseResult[] = [
218+
{
219+
"id": 100000,
220+
"project": {},
221+
"testRun": {
222+
"id": "174"
223+
},
224+
"priority": 0,
225+
"url": "",
226+
"lastUpdatedBy": {
227+
"displayName": null,
228+
"id": null
229+
}
230+
},
231+
{
232+
"id": 100001,
233+
"project": {},
234+
"testRun": {
235+
"id": "174"
236+
},
237+
"priority": 0,
238+
"url": "",
239+
"lastUpdatedBy": {
240+
"displayName": null,
241+
"id": null
242+
}
243+
}
244+
];
245+
246+
export const oAuthToken = {
247+
parameters: { AccessToken: 'token' },
248+
scheme: 'OAuth'
249+
}

0 commit comments

Comments
 (0)