Skip to content

Commit 45b3d2a

Browse files
authored
test: prevent false-positive Java test runner results (#1756)
* test: add Java test navigation autotest plan * test: wait for Java navigation completion * test: require proof of Java test execution * test: focus runner plan on executed tests * test: avoid flaky breakpoint screenshot check
1 parent 5d70612 commit 45b3d2a

4 files changed

Lines changed: 125 additions & 51 deletions

File tree

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package com.example;
22

3+
import java.io.IOException;
4+
import java.nio.file.Files;
5+
import java.nio.file.Path;
36
import org.junit.jupiter.api.Test;
47
import static org.junit.jupiter.api.Assertions.assertEquals;
58

69
public class CalculatorTest {
710

811
@Test
9-
public void testAdd() {
12+
public void testAdd() throws IOException {
1013
Calculator c = new Calculator();
1114
assertEquals(5, c.add(2, 3));
15+
Files.writeString(Path.of("target", "autotest-executed.txt"), "testAdd passed");
1216
}
1317
}

‎test-plans/java-debugger.yaml‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,15 @@ steps:
5656

5757
# ── Set breakpoint ───────────────────────────────────────
5858
# App.java line 5: System.out.println("Hello Java");
59+
# Do not use LLM screenshot verification for the gutter dot: breakpoint
60+
# decorations can render too late on macOS. The later debugStepOver action
61+
# is authoritative — without a working breakpoint this one-line program
62+
# exits during the settle wait and debugStepOver fails with no active
63+
# debug session.
5964
- id: "set-breakpoint"
6065
action: "setBreakpoint 5"
61-
verify: "Red breakpoint dot is shown in the gutter of App.java line 5"
66+
verify: "Debug: Toggle Breakpoint was dispatched for App.java line 5"
67+
skipLlmVerify: true
6268

6369
# ── Start debug session ─────────────────────────────────
6470
- id: "start-debug"
@@ -67,17 +73,12 @@ steps:
6773
timeout: 30
6874

6975
# ── Verify breakpoint hit ───────────────────────────────
70-
# wiki: "verify if the breakpoint is hit". The deterministic ground
71-
# truth is the next step `debugStepOver` — it can only succeed if the
72-
# debugger is paused. The verify text is intentionally lenient: the
73-
# yellow execution-line marker can be off-viewport when the debug
74-
# toolbar pushes the editor down, so we accept either the marker or
75-
# the debug toolbar in paused state as evidence.
76-
- id: "verify-breakpoint"
76+
# Allow the program to reach the breakpoint. The next debugStepOver action
77+
# deterministically fails if the debug session already exited.
78+
- id: "wait-for-breakpoint"
7779
action: "wait 10 seconds"
78-
verify: "Program is paused at the breakpoint — debug toolbar visible in paused state or the yellow execution-line marker appears on/near App.java line 5"
7980

80-
# ── Continue execution ──────────────────────────────────
81+
# ── Verify breakpoint and continue execution ────────────
8182
- id: "continue-debug"
8283
action: "debugStepOver"
8384
verify: "Program has stepped one statement and remains paused (debug toolbar still in paused state)"
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Test Plan: Java Test Navigation
2+
#
3+
# Regression coverage for Java Test Runner navigation between a production
4+
# class and its corresponding test class.
5+
#
6+
# Verifies: LS ready -> Go to Test opens CalculatorTest.java ->
7+
# Go to Test Subject returns to Calculator.java.
8+
#
9+
# Prerequisites:
10+
# - JDK 11+ installed and available
11+
#
12+
# Usage: autotest run test-plans/java-test-navigation.yaml
13+
14+
name: "Java Test Runner - Navigate Between Test and Subject"
15+
description: |
16+
Verifies that Java Test Runner can discover the corresponding test and
17+
production classes and navigate between them using command palette actions.
18+
19+
setup:
20+
extension: "redhat.java"
21+
extensions:
22+
- "vscjava.vscode-java-pack"
23+
preRelease: true
24+
vscodeVersion: "stable"
25+
workspace: "../test-fixtures/maven-junit"
26+
timeout: 360
27+
workspaceSettings:
28+
java.configuration.updateBuildConfiguration: "automatic"
29+
java.import.maven.enabled: true
30+
31+
steps:
32+
- id: "ls-ready"
33+
action: "waitForLanguageServer"
34+
verify: "The maven-junit workspace has loaded and the Java language server is ready"
35+
timeout: 300
36+
skipLlmVerify: true
37+
38+
- id: "open-subject"
39+
action: "open file Calculator.java"
40+
verify: "Calculator.java is open in the editor"
41+
verifyEditor:
42+
fileName: "Calculator.java"
43+
contains: "public class Calculator"
44+
timeout: 15
45+
waitBefore: 5
46+
skipLlmVerify: true
47+
48+
# Test discovery and Java search indexing continue asynchronously after the
49+
# language server reports ready, especially on cold CI runners.
50+
- id: "wait-for-indexing"
51+
action: "wait 90 seconds"
52+
53+
- id: "go-to-test"
54+
action: "run command Java: Go to Test"
55+
verify: "The Java: Go to Test command was selected and dispatched from the command palette"
56+
timeout: 30
57+
waitBefore: 3
58+
skipLlmVerify: true
59+
60+
# Command Palette dismissal only proves that VS Code dispatched the command.
61+
# Navigation completes asynchronously on macOS, so verify the resulting
62+
# editor state in a separate settle step.
63+
- id: "verify-test-open"
64+
action: "wait 15 seconds"
65+
verify: "CalculatorTest.java is the active editor after Java: Go to Test"
66+
verifyEditor:
67+
fileName: "CalculatorTest.java"
68+
contains: "public class CalculatorTest"
69+
timeout: 30
70+
skipLlmVerify: true
71+
72+
- id: "go-to-test-subject"
73+
action: "run command Java: Go to Test Subject"
74+
verify: "The Java: Go to Test Subject command was selected and dispatched from the command palette"
75+
timeout: 30
76+
waitBefore: 3
77+
skipLlmVerify: true
78+
79+
- id: "verify-subject-open"
80+
action: "wait 15 seconds"
81+
verify: "Calculator.java is the active editor after Java: Go to Test Subject"
82+
verifyEditor:
83+
fileName: "Calculator.java"
84+
contains: "public class Calculator"
85+
timeout: 30
86+
skipLlmVerify: true

‎test-plans/java-test-runner.yaml‎

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Test Plan: Java Test Runner (from vscode-java-pack.wiki)
22
#
33
# Source: wiki Test-Plan.md "Java Test Runner" scenario
4-
# Verify: Test panel display → run all tests → CodeLens visible
4+
# Verify: test discovery → run tests → execution marker
55
#
66
# Uses test-fixtures/maven-junit — a self-contained Maven + JUnit 5 fixture
77
# owned by this repo. Upstream `vscode-java/maven/salut` has no @Test files,
@@ -13,10 +13,10 @@
1313
#
1414
# Usage: autotest run test-plans/java-test-runner.yaml
1515

16-
name: "Java Test Runner — Test Panel and CodeLens"
16+
name: "Java Test Runner — Discovery and Execution"
1717
description: |
1818
Corresponds to the Java Test Runner scenario in the wiki Test Plan:
19-
Verify that the test panel displays test cases and tests can be run via the panel or CodeLens.
19+
Verify that Java tests are discovered and actually executed.
2020
2121
setup:
2222
extension: "redhat.java"
@@ -25,12 +25,6 @@ setup:
2525
vscodeVersion: "stable"
2626
workspace: "../test-fixtures/maven-junit"
2727
timeout: 360 # First import needs to download JUnit jars on cold caches
28-
# Force java.test.editor.enableCodelens=true so the Run|Debug CodeLens
29-
# gutter links render reliably in the reopen-test-file verify screenshot.
30-
# The vscode-java-test extension defaults to true but a stale user/Machine
31-
# settings.json on the runner can override it.
32-
workspaceSettings:
33-
java.test.editor.enableCodelens: true
3428

3529
steps:
3630
# ── Wait for LS ready ─────────────────────────────────────────
@@ -45,10 +39,19 @@ steps:
4539
action: "open file CalculatorTest.java"
4640
verify: "CalculatorTest.java is open in the editor and shows a JUnit @Test method"
4741
verifyEditor:
42+
fileName: "CalculatorTest.java"
4843
contains: "@Test"
4944
timeout: 15
5045
waitBefore: 5
5146

47+
- id: "clear-execution-marker"
48+
action: "deleteFile target/autotest-executed.txt"
49+
verify: "Any execution marker from an earlier test run has been removed"
50+
verifyFile:
51+
path: "~/target/autotest-executed.txt"
52+
exists: false
53+
skipLlmVerify: true
54+
5255
# Give the Java Test Runner extension time to scan the project after LS
5356
# ready — discovery is asynchronous and Test Explorer is initially empty.
5457
# On cold-cache CI runners 20s is sometimes too short; bump to 45s.
@@ -63,39 +66,19 @@ steps:
6366
# and runs every test in the project from any context (matches the wiki
6467
# scenario "Run all tests").
6568
#
66-
# The verify text is intentionally agnostic to whether the run produced a
67-
# results panel, an inline "No tests found" hint, or simply dismissed the
68-
# palette — on a cold-cache runner the Java Test Runner's discovery may
69-
# still be in flight when the screenshot is captured. The wait-test-complete
70-
# step below provides the deterministic settle window before any further
71-
# assertion is made.
7269
- id: "run-all-tests"
7370
action: "run command Java: Run Tests"
74-
verify: "Java: Run Tests command has been invoked from the palette; the Java Test Runner extension has responded (this may show as a Testing view becoming active, a run indicator in the status bar, or an informational notification such as 'No tests found in this file' if discovery is still in progress — all of these indicate the command executed successfully)"
71+
verify: "Java: Run Tests was selected and dispatched from the command palette"
7572
waitBefore: 3
76-
# Test discovery is asynchronous in vscode-java-test; on cold-cache
77-
# CI runners the first Run Tests invocation can land before discovery
78-
# completes ("No tests have been found"). Allow one retry — by the
79-
# second attempt the discovery cache is usually warm.
80-
retries: 1
73+
skipLlmVerify: true
8174

82-
- id: "wait-test-complete"
75+
# CalculatorTest writes this marker only after its assertion passes. Missing
76+
# discovery, "No tests found", launch failures, and failed tests therefore
77+
# cannot pass this deterministic verification.
78+
- id: "verify-run-all-executed"
8379
action: "wait 45 seconds"
84-
verify: "Test discovery / execution has settled after the wait; the editor still shows CalculatorTest.java with the @Test method"
85-
86-
# ── Step 3: Re-open test file ──────────
87-
# The @Test annotation in the editor's text content is the deterministic
88-
# ground truth that the test file is loaded and visible. CodeLens
89-
# (Run|Debug) gutter links require the vscode-java-test extension to
90-
# have completed its discovery scan; on a cold runner with newly-
91-
# downloaded JUnit jars they may not be rendered at screenshot time.
92-
# Keep verify text strictly about visible editor content so the LLM
93-
# doesn't downgrade on the CodeLens absence.
94-
- id: "reopen-test-file"
95-
action: "open file CalculatorTest.java"
96-
verify: "CalculatorTest.java is re-opened in the editor; the file's content is shown including the @Test-annotated method"
97-
verifyEditor:
98-
contains: "@Test"
99-
timeout: 10
100-
waitBefore: 5
101-
80+
verify: "CalculatorTest.testAdd completed successfully and wrote its execution marker"
81+
verifyFile:
82+
path: "~/target/autotest-executed.txt"
83+
contains: "testAdd passed"
84+
skipLlmVerify: true

0 commit comments

Comments
 (0)