diff --git a/java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/coverage/CoverageHandler.java b/java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/coverage/CoverageHandler.java index e3cc3e8a..9ccde83e 100644 --- a/java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/coverage/CoverageHandler.java +++ b/java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/coverage/CoverageHandler.java @@ -18,11 +18,13 @@ import com.microsoft.java.test.plugin.util.JUnitPlugin; import com.microsoft.java.test.plugin.util.ProjectTestUtils; +import org.apache.commons.lang3.StringUtils; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jdt.core.IClasspathEntry; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.Signature; import org.eclipse.jdt.internal.core.ClasspathEntry; import org.eclipse.jdt.ls.core.internal.managers.ProjectsManager; import org.jacoco.core.analysis.Analyzer; @@ -192,10 +194,36 @@ private List getMethodCoverages(final Collection methodCoverages.add(new MethodCoverage( methodCoverage.getFirstLine(), methodCoverage.getMethodCounter().getCoveredCount() > 0 ? 1 : 0, - methodCoverage.getName() + getMethodName(methodCoverage) )); } } return methodCoverages; } + + private String getMethodName(IMethodCoverage methodCoverage) { + final String methodName = methodCoverage.getName(); + if ("".equals(methodName) || "".equals(methodName)) { + return methodName; + } + final String signature = methodCoverage.getDesc(); + if (StringUtils.isBlank(signature)) { + return methodName; + } + + try { + final String[] parameterTypes = Signature.getParameterTypes(signature); + final List parameterNames = new LinkedList<>(); + if (parameterTypes.length > 0) { + for (final String parameterType : parameterTypes) { + final String simpleName = Signature.getSignatureSimpleName(parameterType.replace("/", ".")); + parameterNames.add(simpleName); + } + } + return String.format("%s(%s)", methodName, String.join(", ", parameterNames)); + } catch (IllegalArgumentException e) { + return methodName; + } + + } } diff --git a/src/controller/testController.ts b/src/controller/testController.ts index 54429ceb..972b7a8d 100644 --- a/src/controller/testController.ts +++ b/src/controller/testController.ts @@ -35,7 +35,7 @@ export function createTestController(): void { testController.createRunProfile('Run Tests', TestRunProfileKind.Run, runHandler, true, runnableTag); testController.createRunProfile('Debug Tests', TestRunProfileKind.Debug, runHandler, true, runnableTag); if (env.appName.includes('Insiders')) { - testController.createRunProfile('Run Tests with Coverage', TestRunProfileKind.Run, runHandler, false, runnableTag); + testController.createRunProfile('Run Tests with Coverage', TestRunProfileKind.Coverage, runHandler, true, runnableTag); } testController.refreshHandler = () => { @@ -241,7 +241,7 @@ export const runTests: (request: TestRunRequest, option: IRunOption) => any = in await runner.tearDown(); } } - if (request.profile?.label.includes('Coverage')) { + if (request.profile?.kind === TestRunProfileKind.Coverage) { coverageProvider.addProject(projectName); } } @@ -249,7 +249,7 @@ export const runTests: (request: TestRunRequest, option: IRunOption) => any = in return resolve(); }); } finally { - if (request.profile?.label.includes('Coverage')) { + if (request.profile?.kind === TestRunProfileKind.Coverage) { run.coverageProvider = coverageProvider; } run.end(); diff --git a/src/utils/launchUtils.ts b/src/utils/launchUtils.ts index 9b8a0f19..47f3be59 100644 --- a/src/utils/launchUtils.ts +++ b/src/utils/launchUtils.ts @@ -3,7 +3,7 @@ import * as path from 'path'; import * as os from 'os'; -import { DebugConfiguration, TestItem } from 'vscode'; +import { DebugConfiguration, TestItem, TestRunProfileKind } from 'vscode'; import { sendError, sendInfo } from 'vscode-extension-telemetry-wrapper'; import { JavaTestRunnerDelegateCommands } from '../constants'; import { dataCache } from '../controller/testItemDataCache'; @@ -82,7 +82,7 @@ export async function resolveLaunchConfigurationForRunner(runner: BaseRunner, te }; } - if (testContext.profile?.label.includes('Coverage')) { + if (testContext.profile?.kind === TestRunProfileKind.Coverage) { let agentArg: string = `-javaagent:${getJacocoAgentPath()}=destfile=${getJacocoDataFilePath(launchArguments.projectName)}`; if (config?.coverage?.appendResult === false) { agentArg += ',append=false';