From ba0ce1a85c109feb13a2803c37cd7f7e61d3822f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20He=C3=9F?= Date: Thu, 18 Jun 2026 14:05:39 +0200 Subject: [PATCH 1/2] Parse class FQN from .cls file and expose it on OurTestItem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Read the fully-qualified class name from the `Class …` line of every test class while resolving its children, and store it as `ourFqn` on the test item. This decouples the real class identity from the filesystem path under `relativeTestRoot`, which is needed to map the %UnitTest.Manager output back to test items and to build a correct testspec for single-method runs (see #74 for the symptoms). --- src/extension.ts | 6 ++++++ src/localTests.ts | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/extension.ts b/src/extension.ts index fe10335..41b3c72 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -22,6 +22,12 @@ export interface OurTestRun extends vscode.TestRun { export interface OurTestItem extends vscode.TestItem { ourUri?: vscode.Uri; supportsCoverage?: boolean; + // Full class FQN parsed from the `Class …` line of the .cls file. + // Set on class-level items so the debug tracker can map outcome lines + // (which carry the real FQN written by %UnitTest.Manager) back to the + // test item even when the filesystem path under `relativeTestRoot` + // does not mirror the package hierarchy. + ourFqn?: string; } export const allTestRuns: (OurTestRun | undefined)[] = []; diff --git a/src/localTests.ts b/src/localTests.ts index 24dd712..b53b90f 100644 --- a/src/localTests.ts +++ b/src/localTests.ts @@ -67,6 +67,12 @@ async function resolveItemChildren(item: OurTestItem) { // break; // } item.range = new vscode.Range(new vscode.Position(index, 0), new vscode.Position(index + 1, 0)) + // Record the real class FQN so the debug tracker can map outcome lines + // back to this item independently of the filesystem path. + const classMatch = lineText.match(/^Class\s+([%\w\.]+)/); + if (classMatch) { + item.ourFqn = classMatch[1]; + } } const match = lineText.match(/^Method Test(.+)\(/); if (match) { From 5b80081be33ee892453f8a2a91f22b95e928f010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20He=C3=9F?= Date: Thu, 18 Jun 2026 14:05:48 +0200 Subject: [PATCH 2/2] Use class FQN for test lookup and single-method testspec (#74) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the filesystem layout under `relativeTestRoot` does not mirror the package hierarchy of the test classes, the previous code derived a "class name" from the relative path that diverges from the real compiled FQN written by %UnitTest.Manager. Two consequences: * DebugTracker built its method-item lookup key from the FQN reported in stdout but the test-item ids were path-based, so the lookup returned undefined and run.passed/failed/skipped was never called — every method stayed on "skipped" in the UI. * commonRunTestsHandler reused the same path-based id part as the testcase argument of %UnitTest.Manager.RunTest() for single-method runs, so the manager could not find the class and produced no per-method result. Both call sites now prefer the real FQN from OurTestItem.ourFqn (with the previous behaviour as a fallback when no FQN was parsed). --- src/commonRunTestsHandler.ts | 9 ++++++++- src/debugTracker.ts | 24 ++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/commonRunTestsHandler.ts b/src/commonRunTestsHandler.ts index 0f6de4a..84d064a 100644 --- a/src/commonRunTestsHandler.ts +++ b/src/commonRunTestsHandler.ts @@ -306,7 +306,14 @@ export async function commonRunTestsHandler(controller: vscode.TestController, r if (request.include?.length === 1) { const idParts = request.include[0].id.split(":"); if (idParts.length === 5) { - testSpec = `${safeUsername}\\${idParts[3].split(".").slice(0, -1).join("\\")}:${idParts[3]}:${idParts[4]}`; + // The suite subpath mirrors where we copied the .cls file (filesystem-based, from idParts[3]). + // The testcase argument must be the real class FQN as compiled on the server — take it from + // the parent class item's ourFqn, falling back to the filesystem-derived id part when no FQN + // was parsed from the .cls file. + const classItem = request.include[0].parent as OurTestItem | undefined; + const classFqn = classItem?.ourFqn ?? idParts[3]; + const suiteSubPath = idParts[3].split(".").slice(0, -1).join("\\"); + testSpec = `${safeUsername}\\${suiteSubPath}:${classFqn}:${idParts[4]}`; } } diff --git a/src/debugTracker.ts b/src/debugTracker.ts index d93dfc0..dff86c4 100644 --- a/src/debugTracker.ts +++ b/src/debugTracker.ts @@ -1,5 +1,5 @@ import * as vscode from 'vscode'; -import { allTestRuns, loadedTestController, localTestController, OurTestRun } from './extension'; +import { allTestRuns, loadedTestController, localTestController, OurTestItem, OurTestRun } from './extension'; import { refreshHistoryRootItem } from './historyExplorer'; import { processCoverage } from './coverage'; @@ -15,6 +15,11 @@ export class DebugTracker implements vscode.DebugAdapterTracker { private testMethodName?: string; private testDuration?: number; private methodTestMap: Map; + // Maps a class FQN (as written by %UnitTest.Manager in stdout) to the + // corresponding class-level test item. Populated from OurTestItem.ourFqn + // so the lookup works even when the filesystem path under + // `relativeTestRoot` does not mirror the package hierarchy. + private fqnToClassItem: Map; private methodTest?: vscode.TestItem; private failureMessages: vscode.TestMessage[] = []; private skippedMessages: vscode.TestMessage[] = []; @@ -30,11 +35,16 @@ export class DebugTracker implements vscode.DebugAdapterTracker { }; this.testingIdBase = this.session.configuration.testingIdBase; this.methodTestMap = new Map(); + this.fqnToClassItem = new Map(); const addToMethodTestMap = (testItem?: vscode.TestItem) => { if (!testItem) { return; } + const fqn = (testItem as OurTestItem).ourFqn; + if (fqn) { + this.fqnToClassItem.set(fqn, testItem); + } if (testItem.children.size > 0) { testItem.children.forEach(addToMethodTestMap); } else { @@ -83,7 +93,17 @@ export class DebugTracker implements vscode.DebugAdapterTracker { const methodBegin = line.match(/^ Test([\dA-Za-z0-9]+).* begins \.\.\./); if (methodBegin) { this.testMethodName = methodBegin[1]; - this.methodTest = this.methodTestMap.get(`${this.testingIdBase}:${this.className}:Test${this.testMethodName}`); + // Preferred lookup: locate the class by its real FQN (independent of + // filesystem path under `relativeTestRoot`), then take the method child. + const classItem = this.className ? this.fqnToClassItem.get(this.className) : undefined; + if (classItem) { + this.methodTest = classItem.children.get(`${classItem.id}:Test${this.testMethodName}`); + } + // Fallback for items predating ourFqn (and for the LoadedTests path, + // where class items are addressed by their flat id). + if (!this.methodTest) { + this.methodTest = this.methodTestMap.get(`${this.testingIdBase}:${this.className}:Test${this.testMethodName}`); + } this.failureMessages = []; if (this.methodTest) { this.run.started(this.methodTest)