question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

shouldThrow should provide a reference to the caught exception

See original GitHub issue

At 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:closed
  • Created 7 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
sksamuelcommented, May 13, 2016

PS. I put a blog up about testing http://www.51zero.com/blog/testing-in-kotlin

0reactions
sksamuelcommented, May 13, 2016

1.1.5 is on central now, if you want to update docs, please do 😃

https://github.com/kotlintest/kotlintest/commit/55b323e13c45292e89f4b9a3539ab92cfce58b7e

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found