Replies: 3 comments 9 replies
-
IIUC, you'd like to have I think that makes sense and would be simple to add: Subject: [PATCH] Report actual as cause
---
Index: junit-jupiter-api/src/main/java/org/junit/jupiter/api/AssertInstanceOf.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/AssertInstanceOf.java b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/AssertInstanceOf.java
--- a/junit-jupiter-api/src/main/java/org/junit/jupiter/api/AssertInstanceOf.java (revision 65e231c4beb339fd54cfef05c51e07213f9c43dd)
+++ b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/AssertInstanceOf.java (date 1759396665044)
@@ -54,6 +54,7 @@
.message(messageOrSupplier) //
.reason(actualValue == null ? "Unexpected null value" : "Unexpected type") //
.expected(expectedType) //
.actual(actualValue == null ? null : actualValue.getClass()) //
+ .cause(actualValue instanceof Throwable t ? t : null) //
.buildAndThrow();
} |
Beta Was this translation helpful? Give feedback.
-
To be fair, JUnit's |
Beta Was this translation helpful? Give feedback.
-
@marcphilipp, @sormuras, I see |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When
assertInstanceOf
fails withmy reaction is "Okay, show me the stack trace then.", every single time. I eventually end up replacing
assertInstanceOf
calls withContrast this with AssertJ's
assertThatThrownBy(...).isInstanceOf(...)
that reports the stack trace of the exception under test in case of an assertion failure. Could we enhanceassertInstanceOf
to include the stack trace in reports too, please?Edit: To avoid an XY Problem, let me share my problem as minimal and as isolated as possible:
What is the most JUnit idiomatic way to do this?
Beta Was this translation helpful? Give feedback.
All reactions