Skip to content

fix: decouple Gradle test delegation from BSP import#1810

Draft
wenytang-ms wants to merge 4 commits intodevelopfrom
wenyt/decouple-test-runner-from-bsp
Draft

fix: decouple Gradle test delegation from BSP import#1810
wenytang-ms wants to merge 4 commits intodevelopfrom
wenyt/decouple-test-runner-from-bsp

Conversation

@wenytang-ms
Copy link
Copy Markdown
Contributor

Problem

Delegate to Gradle test execution only works when the project is imported via Gradle Build Server (BSP). If the project was imported via Buildship or any other method, the feature silently fails — no test results, no error message. This affects a significant number of users, especially those with:

  • Projects imported before BSP became the default
  • Multi-root workspaces (BSP importer returns false for these)
  • Projects created via Create a new Java Project wizard (incremental import path is hardcoded to return false in BSP importer)
  • Any environment where BSP import didn't succeed for any reason

The root cause is that GradleDelegateCommandHandler.java requires GradleBuildServerProjectNature, which is only present on BSP-imported projects. When absent, it throws IllegalArgumentException, which is caught silently.

Solution

Decouple test execution from BSP by replacing the java.gradle.delegateTest BSP command with direct Gradle task execution via the existing runBuild API (Gradle Language Server / gRPC).

Key changes:

  • GradleTestRunner.ts: Rewritten launch() to run gradle test --tests <filter> through TaskServerClient.runBuild(), then parse JUnit XML results from build/test-results/
  • testResultParser.ts (new): Parses standard JUnit XML test result files
  • BuildServerController.ts: BSP test callbacks replaced with no-ops for backward compatibility
  • Extension.ts: Test runner now receives TaskServerClient directly instead of going through BuildServerController

What this means:

  • Delegate to Gradle now works for ALL Gradle projects regardless of import method
  • Zero dependency on BSP for test execution
  • Debug support preserved (same init script approach)
  • Same TestRunner interface contract with vscode-java-test — no changes needed there

Trade-off: Test results are reported after Gradle finishes (batch) rather than streamed in real-time via BSP notifications. For single test runs (the most common case), this has no visible impact.

Related Issues

Fixes microsoft/vscode-java-test#1771
Fixes microsoft/vscode-java-test#1726
Fixes #1802
Related: microsoft/vscode-java-test#1045

Replace the BSP-dependent test execution path (java.gradle.delegateTest)
with direct Gradle task execution via the existing runBuild API.

Previously, 'Delegate to Gradle' required the project to be imported via
Gradle Build Server (BSP). If the project was imported via Buildship or
any other method, the feature would silently fail with no test results
and no error message shown to the user.

The new implementation:
- Runs 'gradle test --tests <filter>' through the Gradle Language Server
- Parses JUnit XML results from build/test-results/ after execution
- Works for ALL Gradle projects regardless of import method
- Preserves debug support via init script injection
- Keeps the same TestRunner interface contract with vscode-java-test

Fixes microsoft/vscode-java-test#1771
Fixes microsoft/vscode-java-test#1726
Fixes #1802

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
Successfully started running 1 pipeline(s).

The init script sets suspend=y, causing the test JVM to block until
the debugger connects. startJavaDebug must be called before awaiting
runBuild, otherwise neither side can proceed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
Successfully started running 1 pipeline(s).

@wenytang-ms wenytang-ms marked this pull request as draft April 13, 2026 06:53
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
Successfully started running 1 pipeline(s).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
Successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant