-
Notifications
You must be signed in to change notification settings - Fork 64
Include actual exception when shouldThrowTheException
fails
#45
Comments
It is something I could create a pull-request for, if you:
|
|
This looks like a really nice addition.
I initially chose to use the junit exceptions because the IDEs I use (IntelliJ and Eclipse) recognize them and can show a specific window (like a diff window for However, the diff window wouldn't be very useful here, as it just shows the two types. I`d appreciate a pull request, because I don't have a lot time in June at the moment, but would gladly review, merge and release it :-) |
Thanks for the answer, @MarkusAmshove . I will get to it in the next days probably. Already copied a bit of your code in my project to move forward with it, so it is basically "already started" ;) |
@MarkusAmshove : How should we proceed for the contribution? I cannot find a CONTRIBUTING file to guide me.
Please advise! |
You're right, sorry. I'll put it on my TODO list. In the past the contributers all forked this repository and opened a pull request from within the fork :-) |
I will do that then! Thanks for the response. |
@MarkusAmshove : You can assign this issue to me (I cannot perform that change), so no one starts work in parallel. My fork is not at |
@MarkusAmshove : I just realised what you meant by IDE support earlier. I was wondering what you were talking about with the diff view and stuff like that. I just realised that I am using Kluent enclusively with Spek, and when one do so, those nice IDE features disappear. In my current setup (Spek/Kluent), I can only rely on the exception's message to understand what went wrong in my test. Not super nice. There is a LOT of work to do in the Spek plugin for IntelliJ. |
Yeah, I've wanted to port the unittests from Kluent to plain old JUnit, but we now have around 900 tests, so I just keep them that way :-) We're using an old Spek version because it doesn't rely on the IntelliJ plugin (thinking about Eclipse users), maybe it would work as expected on the most recent version of Spek. |
Did you mean "from Spek to JUnit"? |
Yeah, also because Gradle doesn't work well with the Spek version we use (it counts over a thousand tests, which aren't there). But I think this will be fixed when I upgrade Spek |
Any updates on this? |
I will de-a assign myself from it. I haven't used Kotlin in almost 2 years. My focus is on completely different things now. My apologies for never completing this change. |
Actual situation
When a
should throw the exception
fails, the message states:Then I can see the stack trace of that
ComparisonFailure
(at least, in the IDE).Problem
That indicates only the point of failure in the test (the assertion itself), but does not give me any information about the exception that did occur in reality (that was not expected). I need then to trace and/or modify temporarily my test code so it just fails (remove the assertion) and then I can see what happened.
Proposition
Include the actual exception as a cause of the thrown
ComparisonFailure
. That way, we can look at the stack trace to know exactly what happened instead of our expected exception.In
Exceptions.kt
:Before:
After:
That logic should/could be applied to every assertions on exceptions, including the
withMessage
andwithCause
.After effect
From the IDE, we can then click on the stack trace of the exception that caused the assertion to fail to be brought to the line that caused it in the code AND know exactly what happened from its message.
The text was updated successfully, but these errors were encountered: