in src/commands/projectExplorerCommands.ts [13:53]
export async function runTestsFromJavaProjectExplorer(node: any, isDebug: boolean): Promise<void> {
const testLevel: TestLevel = getTestLevel(node._nodeData);
const isHierarchicalMode: boolean = isHierarchical(node._nodeData);
const progressReporter: IProgressReporter | undefined = progressProvider?.createProgressReporter(isDebug ? 'Debug Test' : 'Run Test');
progressReporter?.report('Searching tests...');
const tests: TestItem[] = [];
if (testLevel === TestLevel.Class) {
tests.push(...await updateItemForDocument(node._nodeData.uri));
} else if (testLevel === TestLevel.Package) {
if (!testController?.items.size) {
await loadJavaProjects();
}
const projectName: string = node._project.name;
const projectItem: TestItem | undefined = testController!.items.get(projectName);
if (!projectItem) {
sendError(new Error('The project name of the node in java project explorer cannot be found in test explorer'));
return;
}
await loadChildren(projectItem);
const nodeFsPath: string = Uri.parse(node._nodeData.uri).fsPath;
projectItem.children.forEach((child: TestItem) => {
const itemPath: string = child.uri?.fsPath || '';
if (isHierarchicalMode || node._nodeData.kind === 4 /*packageRoot*/) {
// if the selected node is a package root or the view is in hierarchical mode,
// all the test items whose path start from the path of the selected node will be added
if (itemPath.startsWith(nodeFsPath)) {
tests.push(child);
}
} else {
// in flat mode, we require the paths exact match
if (path.relative(itemPath, nodeFsPath) === '') {
tests.push(child);
}
}
});
}
const request: TestRunRequest = new TestRunRequest(tests, undefined);
await runTests(request, { progressReporter, isDebug });
}