-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Trim internal frames from AssertionFailedError #5159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
mpkorstanje
wants to merge
5
commits into
main
Choose a base branch
from
rien/prune-stacktrace-assertion-builder
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 tasks
a04dd02 to
94360c1
Compare
mpkorstanje
commented
Nov 18, 2025
junit-jupiter-api/src/main/java/org/junit/jupiter/api/AssertionFailureBuilder.java
Show resolved
Hide resolved
When using `JUnit.start` and creating a failing test, users will be confronted with a large stacktrace with mostly irrelevant information. Even after #5158 is merged, the stacktrace will contain several internal frames: ``` org.opentest4j.AssertionFailedError: expected: <11> but was: <12> at org.junit.jupiter.api@6.1.0-SNAPSHOT/org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:158) at org.junit.jupiter.api@6.1.0-SNAPSHOT/org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:139) at org.junit.jupiter.api@6.1.0-SNAPSHOT/org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:201) at org.junit.jupiter.api@6.1.0-SNAPSHOT/org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:152) at org.junit.jupiter.api@6.1.0-SNAPSHOT/org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:147) at org.junit.jupiter.api@6.1.0-SNAPSHOT/org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:558) at com.examp.project/com.example.project.HelloTest.stringLength(HelloTest.java:14) ``` By pruning these internal frames, the stacktrace can be reduced to a much more readable: ``` org.opentest4j.AssertionFailedError: expected: <11> but was: <12> at com.examp.project/com.example.project.HelloTest.stringLength(HelloTest.java:14) ``` Comparable behaviour can be found in AssertJ[1] and IDEA which folds internal frames in the console using `<6 internal line>`. The pruning functionality is intentionally added to the `AssertionFailureBuilder` rather than the `ExceptionUtils` to enable other users of the builder to also prune the internal frames from their own assertions. 1. https://github.com/assertj/assertj/blob/79bdebf1817692e5e0ff5ee3ab097dcd104d47ae/assertj-core/src/main/java/org/assertj/core/util/Throwables.java#L117-L148
94360c1 to
9e04b51
Compare
mpkorstanje
commented
Nov 18, 2025
|
|
||
| @Test | ||
| @Test //TODO: | ||
| void shouldAlwaysKeepJupiterAssumptionStackTraceElement() { |
Contributor
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should assumptions also be trimmed?
Member
|
I think we should preserve the bottomost |
Contributor
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

When using
JUnit.startand creating a failing test, users will be confronted with a large stacktrace with mostly irrelevant information. Even after #5158 is merged, the stacktrace will contain several internal frames:By pruning these internal frames, the stacktrace can be reduced to a much more readable:
Comparable behaviour can be found in AssertJ[1] and IDEA which folds internal frames in the console using
<6 internal lines>.The pruning functionality is intentionally added to the
AssertionFailureBuilderrather than theExceptionUtilsto enable other users to also prune the internal frames from their own assertions.I hereby agree to the terms of the JUnit Contributor License Agreement.
Definition of Done
@APIannotations