shouldThrow should provide a reference to the caught exception
See original GitHub issueAt the moment it is only possible to test whether an exception of a certain was thrown:
shouldThrow<IllegalAccessException> {
// code in here that you expect to throw a IllegalAccessException
}
But sometimes it is necessary to test some details of the exception like the message. This could be done by provider an overloaded shouldThrow
method, which would provide a reference to the exception.
shouldThrow<IllegalAccessException> { exception ->
// code in here that you expect to throw a IllegalAccessException
exception.message should start with "Something went wrong"
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Why should we always catch exceptions by reference?
It is almost always better to pass around objects by ( const ) reference, that's something we learned by heart. But what about...
Read more >Exceptions
Should ().Throw<InvalidOperationException>() .WithMessage("Hello is not allowed at this moment");. But if you prefer the arrange-act-assert syntax, you can ...
Read more >c++ - Why should i use catch by reference when exception ...
Exceptions should be thrown by value and caught by reference, not thrown by pointer. Catching a pointer by reference is pointless (pun).
Read more >Always catch exceptions by reference - C++ on a Friday
The right way to write this would be catch (const Exception& e) , which would result in a reference to the original SpecialException....
Read more >How to Throw Exceptions in Java
You could use a custom exception to collect information like the database URL, username, password, etc. In the catch block, you could write...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
PS. I put a blog up about testing http://www.51zero.com/blog/testing-in-kotlin
1.1.5 is on central now, if you want to update docs, please do 😃
https://github.com/kotlintest/kotlintest/commit/55b323e13c45292e89f4b9a3539ab92cfce58b7e