Skip to content

Commit ff1329a

Browse files
authored
Detect syncTestOutcomeAcrossSuites (#136)
Co-authored-by: bryan cook <3217452+bryancook@users.noreply.github.com>
1 parent 6f1993d commit ff1329a

5 files changed

Lines changed: 80 additions & 3 deletions

File tree

PublishTestPlanResultsV1/context/TestResultContext.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { TestConfiguration, TestPlan, TestPoint } from "azure-devops-node-api/in
22
import { TestResultContextParameters } from "./TestResultContextParameters";
33
import { TestResultContextBuilder } from "./TestResultContextBuilder";
44
import { configAlias } from "./configAlias";
5+
import { TestPoint2 } from "../services/AdoWrapper";
56

67
export class TestResultContext {
78

@@ -17,13 +18,17 @@ export class TestResultContext {
1718

1819
private readonly supportedTestConfigs: Map<string, TestConfiguration>;
1920
private readonly testPoints: Map<number, TestPoint>;
21+
private readonly testCases: Set<string>;
22+
private readonly syncOutcomeAcrossSuites: boolean = false;
2023

2124
constructor(projectId: string, projectName: string, testPlan: TestPlan) {
2225
this.projectId = projectId;
2326
this.projectName = projectName;
2427
this.testPlan = testPlan;
2528
this.supportedTestConfigs = new Map<string, TestConfiguration>();
2629
this.testPoints = new Map<number, TestPoint>();
30+
this.testCases = new Set<string>();
31+
this.syncOutcomeAcrossSuites = this.testPlan.testOutcomeSettings?.syncOutcomeAcrossSuites ?? false;
2732
}
2833

2934
addConfig(config: TestConfiguration) {
@@ -54,6 +59,22 @@ export class TestResultContext {
5459
}
5560

5661
addTestPoint(point: TestPoint) {
62+
63+
// as performance optimization, we can exclude test points that are duplicate test case references
64+
// when the test plan has the "sync outcome across suites" option enabled
65+
if (this.syncOutcomeAcrossSuites) {
66+
// logic to handle duplicate test points
67+
const testCaseId = (point as TestPoint2).testCaseReference.id;
68+
if (testCaseId) {
69+
if (this.testCases.has(testCaseId.toString())) {
70+
// skip adding this test point as it's a duplicate reference to the same test case
71+
return;
72+
}
73+
// add the test case ID to the set to track it
74+
this.testCases.add(testCaseId.toString());
75+
}
76+
}
77+
5778
this.testPoints.set(point.id, point);
5879
}
5980

@@ -91,4 +112,8 @@ export class TestResultContext {
91112
hasConfig(name: string): boolean {
92113
return this.supportedTestConfigs.has(name);
93114
}
115+
116+
hasSyncTestOutcomeEnabled() : boolean {
117+
return this.syncOutcomeAcrossSuites;
118+
}
94119
}

PublishTestPlanResultsV1/context/TestResultContextBuilder.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ export class TestResultContextBuilder {
6464
let points = await this.getTestPoints(projectId, testPlan, testConfigFilterId);
6565
ctx.addTestPoints(points);
6666
this.log.info(`Available Test Points: ${points.length}`);
67+
if (ctx.hasSyncTestOutcomeEnabled()) {
68+
this.log.info(`Test Plan has 'sync outcomes across suites' enabled. Duplicate test case references will be removed.`);
69+
let uniqueTestLength = ctx.getTestPoints().length;
70+
if (points.length != uniqueTestLength) {
71+
this.log.info(`Removed ${points.length - uniqueTestLength} duplicate test case reference(s).`);
72+
}
73+
}
6774

6875
return ctx;
6976
}

PublishTestPlanResultsV1/test/TestResultContextBuilder.specs.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,48 @@ describe("TestResultContextBuilder", () => {
256256
expect((points[3] as TestPoint2).testCaseReference.name).to.eq("Test Case 4");
257257
});
258258
});
259+
260+
context("Sync outcomes across test suites enabled", () => {
261+
it("Should not include duplicate test points that reference the same test case", async () => {
262+
// arrange
263+
setupTestPlans([
264+
newTestPlan(1, "ValidPlan", undefined, true /*sync outcomes across suites*/)
265+
]);
266+
setupTestPoints([
267+
newTestPoint(1, "Test Case 1", "1", "150"),
268+
newTestPoint(2, "Test Case 1 - duplicate", "1", "150"),
269+
newTestPoint(3, "Test Case 2", "1", "151"),
270+
]);
271+
272+
// act
273+
var result = await subject.build();
274+
275+
// assert
276+
let points = result.getTestPoints();
277+
expect(points.length).to.eq(2);
278+
});
279+
});
280+
281+
context("Sync outcomes across test suites not set", () => {
282+
it("Should not duplicate test points that reference the same test case", async () => {
283+
// arrange
284+
setupTestPlans([
285+
newTestPlan(1, "ValidPlan")
286+
]);
287+
setupTestPoints([
288+
newTestPoint(1, "Test Case 1", "1", "150"),
289+
newTestPoint(2, "Test Case 1 - duplicate", "1", "150"),
290+
newTestPoint(3, "Test Case 2", "1", "151"),
291+
]);
292+
293+
// act
294+
var result = await subject.build();
295+
296+
// assert
297+
let points = result.getTestPoints();
298+
expect(points.length).to.eq(3);
299+
});
300+
});
259301
})
260302

261303
context("Load Test Case Meta", () => {

PublishTestPlanResultsV1/test/testUtil.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,15 @@ export function newTestConfig(id : number = 0, name : string = "DefaultConfig")
100100
return <TestConfiguration>{ id: id, name: name};
101101
}
102102

103-
export function newTestPlan(id : number = 0, name? : string, endDate? : Date) : TestPlan {
103+
export function newTestPlan(id : number = 0, name? : string, endDate? : Date, syncOutcomeAcrossSuites? : boolean) : TestPlan {
104104
return <TestPlan> {
105105
id: id,
106106
name: name,
107107
endDate: endDate,
108-
rootSuite: newShallowReference(id.toString(), name as string)
108+
rootSuite: newShallowReference(id.toString(), name as string),
109+
testOutcomeSettings: {
110+
syncOutcomeAcrossSuites: syncOutcomeAcrossSuites
111+
}
109112
};
110113
}
111114

devops/pipelines/marketplace-extension/regression-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ parameters:
5252
buildId: 2436
5353
expectedResults:
5454
- outcome: Passed
55-
count: 2
55+
count: 1
5656

5757
steps:
5858
- pwsh: |

0 commit comments

Comments
 (0)