Skip to content

Commit 770112f

Browse files
authored
Fix the regression bug: assume failure is not marked as skipped (microsoft#946)
1 parent 515f557 commit 770112f

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

src/runners/junitRunner/JUnitRunnerResultAnalyzer.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,8 @@ export class JUnitRunnerResultAnalyzer extends BaseRunnerResultAnalyzer {
7070
this.currentTestItem = testId;
7171
const failedResult: ITestResult = Object.assign({}, testResultManager.getResultById(testId), {
7272
id: testId,
73-
status: TestStatus.Fail,
73+
status: data.indexOf(MessageId.ASSUMPTION_FAILED_TEST_PREFIX) > -1 ? TestStatus.Skip : TestStatus.Fail,
7474
});
75-
if (data.indexOf(MessageId.ASSUMPTION_FAILED_TEST_PREFIX) > -1) {
76-
failedResult.status = TestStatus.Skip;
77-
return;
78-
}
7975
updateElapsedTime(failedResult);
8076
testResultManager.storeResult(failedResult);
8177
this.testIds.add(testId);

test/maven-junit4-suite/codelens.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,22 @@ suite('Code Lens Tests', function() {
150150
assert.ok(failedDetail!.duration !== undefined, 'Should have execution time');
151151
});
152152

153+
test("Assume failure should mark as skipped", async function() {
154+
const document: TextDocument = await workspace.openTextDocument(Uris.JUNIT4_ASSUME_TEST);
155+
await window.showTextDocument(document);
156+
157+
const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider();
158+
const codeLens: CodeLens[] = await codeLensProvider.provideCodeLenses(document, Token.cancellationToken);
159+
const command: Command | undefined = codeLens[0].command;
160+
const testItem: ITestItem[] = command!.arguments as ITestItem[];
161+
await commands.executeCommand(command!.command, testItem[0]);
162+
163+
const projectName: string = testItem[0].project;
164+
const skippedDetail: ITestResult| undefined = testResultManager.getResultById(`${projectName}@junit4.AssumeTest#shouldSkip`);
165+
assert.equal(skippedDetail!.status, TestStatus.Skip, 'Should have skipped case');
166+
assert.ok(skippedDetail!.duration !== undefined, 'Should have execution time');
167+
});
168+
153169
teardown(async function() {
154170
// Clear the result cache
155171
testResultManager.dispose();

test/shared.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export namespace Uris {
2929
export const JUNIT4_RUNWITH: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, JUNIT4_TEST_PACKAGE, 'RunWithAnnotation.java'));
3030
export const JUNIT4_EXCEPTION_BEFORE: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, JUNIT4_TEST_PACKAGE, 'ExceptionInBefore.java'));
3131
export const JUNIT4_PARAMETERIZED_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, JUNIT4_TEST_PACKAGE, 'ParameterizedTest.java'));
32+
export const JUNIT4_ASSUME_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, JUNIT4_TEST_PACKAGE, 'AssumeTest.java'));
3233

3334
const MODULAR_GRADLE: string = path.join('modular-gradle', 'src', 'test', 'java', 'com', 'example', 'project');
3435
export const MODULAR_GRADLE_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, MODULAR_GRADLE, 'GradleModularTest.java'));
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package junit4;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assume.assumeTrue;
6+
7+
public class AssumeTest {
8+
@Test
9+
public void shouldSkip() {
10+
assumeTrue(false);
11+
}
12+
}

0 commit comments

Comments
 (0)