apache / apache/netbeans

junit failed test jumps to wrong test line

Open
#8,567 0 comments 0 reactions 0 assignees View on GitHub
kind:bug tests
Dominant language
Java
Stars
3.1k
Forks
935
Avg merge
2d 3h
Merged PRs (30d)
17

Description

### Apache NetBeans version

Apache NetBeans 26

### What happened

When running JUnit tests within NetBeans, depending on the test, the UI jumps to the wrong line when you select 'go to source' for a failed test.

To recreate this situation, do the following.

### Language / Project Type / NetBeans Component

_No response_

### How to reproduce

Build NetBeans.
To make a test fail, modify one of the tests in RenameRecordTest.java for instance, the first by
changing the expected class name 'Use' to read 'Ase'. This will make the test fail.

Test the file (or the single method) with the test results window open.
After some time the UI will report that the test failed.
On the failing test right-click and select 'go to source'.
In this case, you will land in the file RefactoringTestBase.java at line 489 in method #runTest at the line `super.runTest();`. This is a helper method in the same test package and is used by many test classes there for reasons, before my time.

The problem is that this is not the source of the test case.
The file we landed on is not really relevant because it is in the wrong location. It is not the test we care about.
We should have landed at a line within the test method in, particular where the method `verifyContent` is invoked.

The stack trace is evaluated by NetBeans to locate the failing test, typically an assert.
It does this 'bottom up' and tries to skip the stack frames that are not part of the user tests.
It does this by assuming that files that share the same parent (directory) as the test file are the ones to look in, including the file itself, of course.

I replayed these tests today, 2026-03-30, to verify that an up-to-date version of NetBeans behaves as described here. I tested it with 29. It still shows the behaviour described here.

In my opinion, a better approach would be to evaluate the stack trace top to bottom, trying to find the
fully qualified name of the __test method__, and to that method extract the line number.

### Did this work correctly in an earlier version?

No / Don't know

### Operating System

ubuntu 24.04

### JDK

jdk 17

### Apache NetBeans packaging

Apache NetBeans binary zip

### Anything else

This issue can be resolved by changing the order of stack evaluation from 'bottom to top' to 'top to bottom´.

### Are you willing to submit a pull request?

Yes

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure by changing the expected class name in RenameRecordTest.java and use the test results window's “go to source” action. Compare the incorrect location in RefactoringTestBase.java at line 489 with the test method and its verifyContent invocation. Done means a failed test opens at the relevant assertion or test-method line rather than the shared helper.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.