diff --git a/extension.bundle.ts b/extension.bundle.ts index beda0ebc..86c8ac1e 100644 --- a/extension.bundle.ts +++ b/extension.bundle.ts @@ -6,3 +6,4 @@ export * from './src/codelens/TestCodeLensProvider'; export * from './src/runners/models'; export * from './src/testResultManager'; export * from './src/protocols'; +export * from './src/utils/commandUtils'; diff --git a/java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/util/TestSearchUtils.java b/java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/util/TestSearchUtils.java index 68f8190c..2b4b68de 100644 --- a/java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/util/TestSearchUtils.java +++ b/java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/util/TestSearchUtils.java @@ -240,9 +240,13 @@ public static List searchLocation(List arguments, IProgressMon if (arguments == null || arguments.size() == 0) { throw new IllegalArgumentException("Invalid aruguments to search the location."); } - // For now, input will only be a method. - final String methodFullName = ((String) arguments.get(0)).replaceAll("[$#]", "."); - final SearchPattern pattern = SearchPattern.createPattern(methodFullName, IJavaSearchConstants.METHOD, + String searchString = ((String) arguments.get(0)).replaceAll("[$#]", "."); + int searchFor = IJavaSearchConstants.METHOD; + if (searchString.endsWith("")) { + searchString = searchString.substring(0, searchString.indexOf("") - 1); + searchFor = IJavaSearchConstants.CLASS; + } + final SearchPattern pattern = SearchPattern.createPattern(searchString, searchFor, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH); final IJavaProject[] projects = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()) .getJavaProjects(); @@ -251,10 +255,10 @@ public static List searchLocation(List arguments, IProgressMon @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { final Object element = match.getElement(); - if (element instanceof IMethod) { - final IMethod method = (IMethod) element; - searchResult.add(new Location(JDTUtils.getFileURI(method.getResource()), - TestItemUtils.parseTestItemRange(method))); + if (element instanceof IMethod || element instanceof IType) { + final IJavaElement javaElement = (IJavaElement) element; + searchResult.add(new Location(JDTUtils.getFileURI(javaElement.getResource()), + TestItemUtils.parseTestItemRange(javaElement))); } } }; diff --git a/src/runners/junitRunner/JUnitRunnerResultAnalyzer.ts b/src/runners/junitRunner/JUnitRunnerResultAnalyzer.ts index 03bb322d..f244dfec 100644 --- a/src/runners/junitRunner/JUnitRunnerResultAnalyzer.ts +++ b/src/runners/junitRunner/JUnitRunnerResultAnalyzer.ts @@ -110,7 +110,7 @@ export class JUnitRunnerResultAnalyzer extends BaseRunnerResultAnalyzer { // In case the output is class level, i.e.: `%ERROR 2,a.class.FullyQualifiedName` const indexOfSpliter: number = message.lastIndexOf(','); if (indexOfSpliter > -1) { - return `${this.projectName}@${message.slice(indexOfSpliter + 1)}#TestError`; + return `${this.projectName}@${message.slice(indexOfSpliter + 1)}#`; } logger.error(`Failed to parse the message: ${message}`); diff --git a/test/maven-junit4-suite/codelens.test.ts b/test/maven-junit4-suite/codelens.test.ts index 7fe5b16e..48215cac 100644 --- a/test/maven-junit4-suite/codelens.test.ts +++ b/test/maven-junit4-suite/codelens.test.ts @@ -120,7 +120,7 @@ suite('Code Lens Tests', function() { await await commands.executeCommand(command!.command, testItem[0]); const projectName: string = testItem[0].project; - const failedDetail: ITestResult| undefined = testResultManager.getResultById(`${projectName}@junit4.ExceptionInBefore#TestError`); + const failedDetail: ITestResult| undefined = testResultManager.getResultById(`${projectName}@junit4.ExceptionInBefore#`); assert.equal(failedDetail!.status, TestStatus.Fail, 'Should have failed case'); assert.ok(failedDetail!.trace !== undefined, 'Should have error trace'); }); diff --git a/test/maven-junit4-suite/commandUtils.test.ts b/test/maven-junit4-suite/commandUtils.test.ts new file mode 100644 index 00000000..dcadbe3a --- /dev/null +++ b/test/maven-junit4-suite/commandUtils.test.ts @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. + +import * as assert from 'assert'; +import { commands, TextDocument, window, workspace, extensions } from 'vscode'; +import { searchTestLocation, ILocation } from '../../extension.bundle'; +import { Uris } from '../shared'; + +suite('Command Utils Tests', function() { + + suiteSetup(async function() { + await extensions.getExtension('vscjava.vscode-java-test')!.activate(); + }); + + test("Can search location for items", async function() { + const document: TextDocument = await workspace.openTextDocument(Uris.JUNIT4_TEST); + await window.showTextDocument(document); + + const location: ILocation[] = await searchTestLocation('junit4.ExceptionInBefore#'); + assert.ok(location); + assert.ok(location.length === 1); + assert.equal(location[0].uri, Uris.JUNIT4_EXCEPTION_BEFORE); + }); + + teardown(async function() { + await commands.executeCommand('workbench.action.closeActiveEditor'); + }); +});