Skip to content

Conversation

@vy
Copy link
Contributor

@vy vy commented Oct 9, 2025

As agreed in this discussion, enrich assertInstanceOf failure with cause.

jshell demonstration

$ jshell --class-path opentest4j-1.3.0.jar:junit-platform-commons-6.1.0-SNAPSHOT.jar:junit-jupiter-api-6.1.0-SNAPSHOT.jar
|  Welcome to JShell -- Version 25
|  For an introduction type: /help intro

jshell> org.junit.jupiter.api.Assertions.assertInstanceOf(RuntimeException.class, new java.io.IOException())
|  Exception org.opentest4j.AssertionFailedError: Unexpected type, expected: <java.lang.RuntimeException> but was: <java.io.IOException>
|        at AssertionFailureBuilder.build (AssertionFailureBuilder.java:158)
|        at AssertionFailureBuilder.buildAndThrow (AssertionFailureBuilder.java:139)
|        at AssertInstanceOf.assertInstanceOf (AssertInstanceOf.java:59)
|        at AssertInstanceOf.assertInstanceOf (AssertInstanceOf.java:35)
|        at Assertions.assertInstanceOf (Assertions.java:3688)
|        at (#1:1)
|  Caused by: java.io.IOException
|        ...

Note the Caused by: java.io.IOException at the end, which is added by this PR.

@marcphilipp marcphilipp added this to the 6.1.0-M1 milestone Oct 9, 2025
@marcphilipp marcphilipp merged commit c9488c1 into junit-team:main Oct 9, 2025
16 checks passed
@marcphilipp
Copy link
Member

Thanks, @vy! 👍

@vy vy deleted the assertInstanceOf-cause branch October 9, 2025 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants