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
Describe actual Throwables when ThrowableAssert fails #1355
Comments
do you mean printing the stack trace at the end of the error message ? can you give an example of what you would ideally have ? |
Example of my ideal message: Expecting Throwable message:
<"expected exception message">
but was:
<"some other unexpected exception">
Throwable that failed the check:
Exception in thread "main" java.lang.RuntimeException: some other unexpected exception
at Test.functionThatIsSupposedToThrowExpectedException(Test.java:119)
at Test.main(Test.java:69)
Caused by: java.lang.RuntimeException: unexpected exception in recurseToGenerateSomeStack
at Test.recurseToGenerateSomeStack(Test.java:133)
at Test.recurseToGenerateSomeStack(Test.java:138)
at Test.recurseToGenerateSomeStack(Test.java:138)
at Test.recurseToGenerateSomeStack(Test.java:138)
at Test.recurseToGenerateSomeStack(Test.java:138)
at Test.recurseToGenerateSomeStack(Test.java:138)
at Test.recurseToGenerateSomeStack(Test.java:138)
at Test.recurseToGenerateSomeStack(Test.java:138)
at Test.recurseToGenerateSomeStack(Test.java:138)
at Test.recurseToGenerateSomeStack(Test.java:138)
at Test.recurseToGenerateSomeStack(Test.java:138)
at Test.recurseToGenerateSomeStack(Test.java:138)
at Test.functionThatIsSupposedToThrowExpectedException(Test.java:115)
... 1 more
Caused by: java.lang.RuntimeException: the root cause of test failure
at Test.f(Test.java:169)
at Test.e(Test.java:164)
at Test.d(Test.java:159)
at Test.c(Test.java:154)
at Test.b(Test.java:149)
at Test.a(Test.java:144)
at Test.recurseToGenerateSomeStack(Test.java:129)
... 13 more Such message allows to immediately learn the real cause of test failure. |
Fair enough, @jakubzytka would you like to contribute it? |
I have done it for the |
Submitted #1630 to do the same for |
Hello, is this issue still open ? I did try the various method asserting the messages in |
|
Hello, I did a first pull request to fix the hasMessageContaining and hasMessageContainingAll assertions, let me know if this is correct. Next steps is to investigate and fix which methods can still be improved, here is a list to be refined of potential classes to be adapted:
|
Hi, I've created a PR fixing the |
Is anybody working on this? If not, can I? |
thanks @weiyilei, I have assigned you |
thank u bro, but I am really confused about what kind of reference will be required in this issue, can u give me an example plz |
Hi bro, I still have no idea about what does the cause reference mean, as I know A.getcause() can get the throwable which lead to A, so what's its reference. :( |
should I use getStackTrace() or getSuppressed(), or import org.openjdk.jol.vm.VM and use VM.current().addressof() |
ShouldHaveCauseInstance is the example |
Hi, I am wondering if the content of ShouldHaveCauseReference_create_Test.java should be modified, or I should just fill the methods of ShouldHaveCauseReference according to the test content |
I'm not sure I understand the question, if you modify ShouldHaveCauseReference you have to write the tests that proves your changes are working and thus you would need to add test cases in ShouldHaveCauseReference_create_Test |
@weiyilei if you still don't understand what I'm saying it means you are not yet ready to contribute and you need a bit more experience before doing so. The AssertJ team is working on its spare time maintaining this project, it's not that we don't want to help junior devs to contribute, it's just that we don't have the time to do so. |
Hi bro, I have tried my best to understand ur requirements and finished my codes following the example of CauseInstance, I have a pull request and let me know if there is something I need to improve. thanks |
@joel-costigliola Hi, I'm interested in this issue. Is there any available task for me to do? |
Hi @joel-costigliola I created a PR to update the ShouldHaveCause with Stacktrace. Please let me know if there is a problem. |
Hi @joel-costigliola, Thanks for reviewing my earlier PR. I have created a new one for ShouldHaveRootCauseInstance and ShouldHaveRootCauseExactlyInstance. Please let me know if there is any problem with the same. |
Hi @joel-costigliola , can ShouldHaveCauseExactlyInstance be marked as done now? Also I have a PR up for ShouldHaveCauseInstance. |
Summary
When some
Throwable
-related assertion fails the actualThrowable
that failed the check is not described beyond what actually caused assertion failure (e.g. message mismatch). In non-trivial code when unexpectedException
s are thrown this makes debugging inconvenient.Dumping more comprehensive (class, message, stack, perhaps even recursive info about causes) info about the actual
Throwable
could ease assertion failure investigation.Relevant message factories (e.g.
ShouldHaveMessage
) already have access to actualThrowable
.It may be tempting to use
util.Throwables.ERROR_DESCRIPTION_EXTRACTOR
to describe throwables, but a more powerful mechanism would be appreciated.Providing precise information in case of assertion failure doesn't seem to be overkill (unlike as in #864)
Error message to improve
If you are interested in contributing to this issue, select one error message, it will be assigned to you.
The text was updated successfully, but these errors were encountered: