Skip to content

Commit acf6b1b

Browse files
authored
bugfix: wrong test result for parameterized tests (microsoft#1027)
1 parent 9b7a583 commit acf6b1b

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/runners/junitRunner/JUnitRunnerResultAnalyzer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ export class JUnitRunnerResultAnalyzer extends BaseRunnerResultAnalyzer {
6565
return;
6666
}
6767
if (finishedResult.status === TestStatus.Running) {
68-
finishedResult.status = TestStatus.Pass;
68+
if (finishedResult.trace) {
69+
finishedResult.status = TestStatus.Fail;
70+
} else {
71+
finishedResult.status = TestStatus.Pass;
72+
}
6973
}
7074
updateElapsedTime(finishedResult);
7175
testResultManager.storeResult(finishedResult);

test/gradle-junit5-suite/codelens.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ suite('Code Lens Tests', function() {
1919

2020
const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider();
2121
const codeLens: CodeLens[] = await codeLensProvider.provideCodeLenses(document, Token.cancellationToken);
22-
assert.equal(codeLens.length, 4, 'Code Lens should appear for @ParameterizedTest annotation');
22+
assert.equal(codeLens.length, 6, 'Code Lens should appear for @ParameterizedTest annotation');
2323

2424
const command: Command | undefined = codeLens[0].command;
2525
assert.notEqual(command, undefined, 'Command inside Code Lens should not be undefined');
@@ -39,6 +39,26 @@ suite('Code Lens Tests', function() {
3939
assert.ok(passedDetail!.duration !== undefined, 'Should have execution time');
4040
});
4141

42+
test("Can get correct result", async function() {
43+
const document: TextDocument = await workspace.openTextDocument(Uris.GRADLE_JUNIT5_PARAMETERIZED_TEST);
44+
await window.showTextDocument(document);
45+
46+
const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider();
47+
const codeLens: CodeLens[] = await codeLensProvider.provideCodeLenses(document, Token.cancellationToken);
48+
49+
const command: Command | undefined = codeLens[2].command;
50+
51+
const testItem: ITestItem[] = command!.arguments as ITestItem[];
52+
53+
await commands.executeCommand(command!.command, testItem[0]);
54+
55+
const projectName: string = testItem[0].project;
56+
57+
const failedDetail: ITestResult| undefined = testResultManager.getResultById(`${projectName}@junit5.ParameterizedAnnotationTest#equal`);
58+
assert.equal(failedDetail!.status, TestStatus.Fail);
59+
assert.ok(failedDetail!.trace !== undefined, 'Should have error trace');
60+
});
61+
4262
test("Can run test method annotated with @Testable", async function() {
4363
const document: TextDocument = await workspace.openTextDocument(Uris.GRADLE_JUNIT5_PROPERTY_TEST);
4464
await window.showTextDocument(document);

test/test-projects/junit5/src/test/java/junit5/ParameterizedAnnotationTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,13 @@ public void canRunWithComment(String str, Boolean bool) throws Exception {
1717
App classUnderTest = new App();
1818
assertEquals(classUnderTest.getGreeting().equals(str), bool);
1919
}
20+
21+
@ParameterizedTest
22+
@CsvSource({
23+
"1, 2",
24+
"1, 1"
25+
})
26+
public void equal(int first, int second) throws Exception {
27+
assertEquals(first, second);
28+
}
2029
}

0 commit comments

Comments
 (0)