Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/controller/testController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ export const runTests: (request: TestRunRequest, option: IRunOption) => any = in
return Promise.resolve(coverageProvider!.getCoverageDetails(fileCoverage.uri));
};
}
const testRunner: TestRunner | undefined = testRunnerService.getRunner(request.profile?.label, request.profile?.kind);
if (testRunner) {
enqueueTestMethods(testItems, run);
}

try {
await new Promise<void>(async (resolve: () => void): Promise<void> => {
Expand All @@ -195,7 +199,6 @@ export const runTests: (request: TestRunRequest, option: IRunOption) => any = in
disposables.forEach((d: Disposable) => d.dispose());
return resolve();
});
enqueueTestMethods(testItems, run);
// TODO: first group by project, then merge test methods.
const queue: TestItem[][] = mergeTestMethods(testItems);
for (const testsInQueue of queue) {
Expand All @@ -219,7 +222,6 @@ export const runTests: (request: TestRunRequest, option: IRunOption) => any = in
profile: request.profile,
testConfig: await loadRunConfig(itemsPerProject, workspaceFolder),
};
const testRunner: TestRunner | undefined = testRunnerService.getRunner(request.profile?.label, request.profile?.kind);
if (testRunner) {
await executeWithTestRunner(option, testRunner, testContext, run, disposables);
disposables.forEach((d: Disposable) => d.dispose());
Expand Down
22 changes: 2 additions & 20 deletions src/controller/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function updateOrCreateTestItem(parent: TestItem, childData: IJavaTestIte

function updateTestItem(testItem: TestItem, metaInfo: IJavaTestItem): void {
testItem.range = asRange(metaInfo.range);
testItem.label = `${getCodiconLabel(metaInfo.testLevel)} ${metaInfo.label}`;
testItem.label = metaInfo.label;
dataCache.set(testItem, {
jdtHandler: metaInfo.jdtHandler,
fullName: metaInfo.fullName,
Expand All @@ -148,7 +148,7 @@ export function createTestItem(metaInfo: IJavaTestItem, parent?: TestItem): Test
}
const item: TestItem = testController.createTestItem(
metaInfo.id,
`${getCodiconLabel(metaInfo.testLevel)} ${metaInfo.label}`.trim(),
metaInfo.label,
metaInfo.uri ? Uri.parse(metaInfo.uri) : undefined,
);
item.range = asRange(metaInfo.range);
Expand All @@ -172,24 +172,6 @@ export function createTestItem(metaInfo: IJavaTestItem, parent?: TestItem): Test
return item;
}

/**
* Get codicon label based on the test level.
*/
function getCodiconLabel(testLevel: TestLevel): string {
switch (testLevel) {
case TestLevel.Project:
return '$(project)';
case TestLevel.Package:
return '$(symbol-namespace)';
case TestLevel.Class:
return '$(symbol-class)';
case TestLevel.Method:
return '$(symbol-method)';
default:
return '';
}
}

let updateNodeForDocumentTimeout: NodeJS.Timer;
/**
* Update test item in a document with adaptive debounce enabled.
Expand Down
97 changes: 1 addition & 96 deletions src/runners/baseRunner/RunnerResultAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
// Licensed under the MIT license.

import { Location, MarkdownString, TestItem } from 'vscode';
import { dataCache, ITestItemData } from '../../controller/testItemDataCache';
import { IRunTestContext, TestLevel, TestResultState } from '../../java-test-runner.api';
import { IRunTestContext } from '../../java-test-runner.api';
import { processStackTraceLine } from '../utils';

export abstract class RunnerResultAnalyzer {
// Track parent test item states to update them when all children complete
protected parentStates: Map<TestItem, ParentItemState> = new Map();

constructor(protected testContext: IRunTestContext) { }

public abstract analyzeData(data: string): void;
Expand Down Expand Up @@ -40,95 +36,4 @@ export abstract class RunnerResultAnalyzer {
return stacktrace.includes(s);
});
}

/**
* Initialize parent state tracking for a test item.
* Counts how many method-level children are being tested.
*/
protected initializeParentState(item: TestItem, triggeredTestsMapping: Map<string, TestItem>): void {
const parent: TestItem | undefined = item.parent;
if (!parent) {
return;
}

const parentData: ITestItemData | undefined = dataCache.get(parent);
if (!parentData || parentData.testLevel !== TestLevel.Class) {
return;
}

if (!this.parentStates.has(parent)) {
// Count how many method-level children are being tested (only count triggered tests)
let childCount: number = 0;
parent.children.forEach((child: TestItem) => {
const childData: ITestItemData | undefined = dataCache.get(child);
if (childData?.testLevel === TestLevel.Method && triggeredTestsMapping.has(child.id)) {
childCount++;
}
});

this.parentStates.set(parent, {
started: false,
childrenTotal: childCount,
childrenCompleted: 0,
hasFailure: false,
});
}
}

/**
* Update parent test item when a child test starts.
* Marks the parent as "started" when the first child starts.
*/
protected updateParentOnChildStart(item: TestItem): void {
const parent: TestItem | undefined = item.parent;
if (!parent) {
return;
}

const parentState: ParentItemState | undefined = this.parentStates.get(parent);
if (parentState && !parentState.started) {
parentState.started = true;
this.testContext.testRun.started(parent);
}
}

/**
* Update parent test item when a child test completes.
* Marks the parent as "passed" or "failed" when all children complete.
*/
protected updateParentOnChildComplete(item: TestItem, childState: TestResultState): void {
const parent: TestItem | undefined = item.parent;
if (!parent) {
return;
}

const parentState: ParentItemState | undefined = this.parentStates.get(parent);
if (!parentState) {
return;
}

// Consider failed or errored tests as failures for the parent
if (childState === TestResultState.Failed ||
childState === TestResultState.Errored) {
parentState.hasFailure = true;
}

parentState.childrenCompleted++;

// Check if all children have completed
if (parentState.childrenCompleted >= parentState.childrenTotal && parentState.childrenTotal > 0) {
if (parentState.hasFailure) {
this.testContext.testRun.failed(parent, []);
} else {
this.testContext.testRun.passed(parent);
}
}
}
}

interface ParentItemState {
started: boolean;
childrenTotal: number;
childrenCompleted: number;
hasFailure: boolean;
}
63 changes: 43 additions & 20 deletions src/runners/junitRunner/JUnitRunnerResultAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export class JUnitRunnerResultAnalyzer extends RunnerResultAnalyzer {
private triggeredTestsMapping: Map<string, TestItem> = new Map();
private projectName: string;
private incompleteTestSuite: ITestInfo[] = [];
private enqueuedTests: Set<TestItem> = new Set();
private suiteItems: Set<TestItem> = new Set();

// tests may be run concurrently, so each item's current state needs to be remembered
private currentStates: Map<TestItem, CurrentItemState> = new Map();
Expand Down Expand Up @@ -67,27 +69,30 @@ export class JUnitRunnerResultAnalyzer extends RunnerResultAnalyzer {
if (data.startsWith(MessageId.TestTree)) {
this.enlistToTestMapping(data.substring(MessageId.TestTree.length).trim());
} else if (data.startsWith(MessageId.TestStart)) {
const item: TestItem | undefined = this.getTestItem(data.substr(MessageId.TestStart.length));
if (!item) {
const testInfo: ITestInfo | undefined = this.getTestInfo(data.substr(MessageId.TestStart.length));
if (!testInfo?.testItem) {
return;
}
this.initializeParentState(item, this.triggeredTestsMapping);
const item: TestItem = testInfo.testItem;
this.setCurrentState(item, TestResultState.Running, 0);
this.setDurationAtStart(this.getCurrentState(item));
setTestState(this.testContext.testRun, item, this.getCurrentState(item).resultState);
this.updateParentOnChildStart(item);
if (!testInfo.isSuite) {
setTestState(this.testContext.testRun, item, this.getCurrentState(item).resultState);
}
} else if (data.startsWith(MessageId.TestEnd)) {
const item: TestItem | undefined = this.getTestItem(data.substr(MessageId.TestEnd.length));
if (!item) {
const testInfo: ITestInfo | undefined = this.getTestInfo(data.substr(MessageId.TestEnd.length));
if (!testInfo?.testItem) {
return;
}
const item: TestItem = testInfo.testItem;
const currentState: CurrentItemState = this.getCurrentState(item);
this.calcDurationAtEnd(currentState);
this.determineResultStateAtEnd(data, currentState);
setTestState(this.testContext.testRun, item, currentState.resultState, undefined, currentState.duration);
const itemData: ITestItemData | undefined = dataCache.get(item);
if (itemData?.testLevel === TestLevel.Method) {
this.updateParentOnChildComplete(item, currentState.resultState);
const shouldReportSuite: boolean = currentState.resultState === TestResultState.Failed ||
currentState.resultState === TestResultState.Errored ||
(currentState.resultState === TestResultState.Skipped && testInfo.testCount === 0);
if (!testInfo.isSuite || shouldReportSuite) {
setTestState(this.testContext.testRun, item, currentState.resultState, undefined, currentState.duration);
}
Comment thread
wenytang-ms marked this conversation as resolved.
} else if (data.startsWith(MessageId.TestFailed)) {
const item: TestItem | undefined = this.getTestItem(data.substr(MessageId.TestFailed.length));
Expand Down Expand Up @@ -121,14 +126,18 @@ export class JUnitRunnerResultAnalyzer extends RunnerResultAnalyzer {
return;
}
const currentResultState: TestResultState = this.getCurrentState(this.tracingItem).resultState;
if (this.assertionFailure) {
this.tryAppendMessage(this.tracingItem, this.assertionFailure, currentResultState);
}
if (this.traces?.value) {
this.tryAppendMessage(this.tracingItem, new TestMessage(this.traces), currentResultState);
}
if (currentResultState === TestResultState.Errored) {
setTestState(this.testContext.testRun, this.tracingItem, currentResultState);
const isSkippedSuite: boolean = currentResultState === TestResultState.Skipped &&
this.suiteItems.has(this.tracingItem);
if (!isSkippedSuite) {
if (this.assertionFailure) {
this.tryAppendMessage(this.tracingItem, this.assertionFailure, currentResultState);
}
Comment thread
wenytang-ms marked this conversation as resolved.
if (this.traces?.value) {
this.tryAppendMessage(this.tracingItem, new TestMessage(this.traces), currentResultState);
}
if (currentResultState === TestResultState.Errored) {
setTestState(this.testContext.testRun, this.tracingItem, currentResultState);
}
}
this.recordingType = RecordingType.None;
} else if (data.startsWith(MessageId.ExpectStart)) {
Expand Down Expand Up @@ -192,8 +201,12 @@ export class JUnitRunnerResultAnalyzer extends RunnerResultAnalyzer {
}

protected getTestItem(message: string): TestItem | undefined {
return this.getTestInfo(message)?.testItem;
}

private getTestInfo(message: string): ITestInfo | undefined {
const index: string = message.substring(0, message.indexOf(',')).trim();
return this.testOutputMapping.get(index)?.testItem;
return this.testOutputMapping.get(index);
}

protected getTestId(message: string): string {
Expand Down Expand Up @@ -406,6 +419,7 @@ export class JUnitRunnerResultAnalyzer extends RunnerResultAnalyzer {
testId,
testCount,
testItem,
isSuite,
});
}

Expand All @@ -424,7 +438,15 @@ export class JUnitRunnerResultAnalyzer extends RunnerResultAnalyzer {
testId,
testCount,
testItem,
isSuite,
});
if (isSuite && testItem) {
this.suiteItems.add(testItem);
}
if (!isSuite && testItem && !this.enqueuedTests.has(testItem)) {
this.enqueuedTests.add(testItem);
this.testContext.testRun.enqueued(testItem);
}
}
}

Expand Down Expand Up @@ -526,6 +548,7 @@ interface ITestInfo {
testId: string;
testCount: number;
testItem: TestItem | undefined;
isSuite: boolean;
}

enum RecordingType {
Expand Down
13 changes: 5 additions & 8 deletions src/runners/testngRunner/TestNGRunnerResultAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT license.

import { Location, MarkdownString, TestItem, TestMessage } from 'vscode';
import { dataCache, ITestItemData } from '../../controller/testItemDataCache';
import { dataCache } from '../../controller/testItemDataCache';
import { RunnerResultAnalyzer } from '../baseRunner/RunnerResultAnalyzer';
import { setTestState } from '../utils';
import { IRunTestContext, TestLevel, TestResultState } from '../../java-test-runner.api';
Expand Down Expand Up @@ -33,6 +33,7 @@ export class TestNGRunnerResultAnalyzer extends RunnerResultAnalyzer {
}
if (testLevel === TestLevel.Method) {
this.triggeredTestsMapping.set(item.id, item);
this.testContext.testRun.enqueued(item);
} else {
item.children.forEach((child: TestItem) => {
queue.push(child);
Expand Down Expand Up @@ -73,10 +74,8 @@ export class TestNGRunnerResultAnalyzer extends RunnerResultAnalyzer {
if (!item) {
return;
}
this.initializeParentState(item, this.triggeredTestsMapping);
this.currentTestState = TestResultState.Running;
this.testContext.testRun.started(item);
this.updateParentOnChildStart(item);
} else if (outputData.name === TEST_FAIL) {
const item: TestItem | undefined = this.getTestItem(id);
if (!item) {
Expand Down Expand Up @@ -114,10 +113,6 @@ export class TestNGRunnerResultAnalyzer extends RunnerResultAnalyzer {
}
const duration: number | undefined = this.parseDuration(attributes.duration);
setTestState(this.testContext.testRun, item, this.currentTestState, undefined, duration);
const itemData: ITestItemData | undefined = dataCache.get(item);
if (itemData?.testLevel === TestLevel.Method) {
this.updateParentOnChildComplete(item, this.currentTestState);
}
}
}

Expand All @@ -141,7 +136,9 @@ export class TestNGRunnerResultAnalyzer extends RunnerResultAnalyzer {
message += `\n${attributes.trace}`;
}
const testMessage: TestMessage = new TestMessage(message);
for (const item of this.testContext.testItems) {
const testCases: Set<TestItem> = new Set(this.triggeredTestsMapping.values());
const items: Iterable<TestItem> = testCases.size > 0 ? testCases : this.testContext.testItems;
for (const item of items) {
this.testContext.testRun.errored(item, testMessage);
}
}
Expand Down
Loading
Loading