Testing exception messages
See original GitHub issueRe discussion in #1052, what is the general consensus on testing for exception messages? The way I see it, there are a few ways we can handle this (in order of work required):
- Ignore exception messages
- Test only for exception messages that are explicitly included in the canonical data for the exercise
- When exception messages are not explicitly stated in the canonical data, require that the exercise contributor invent messages for all expected exceptions
Additionally, if we are to test for exception messages at all, we need to have a conventional method of doing so in both Python2 and Python3. assertRaisesRegexp
is replaced by assertRaisesRegex
in Python3, so as mentioned in #1052 there are a few ways of handling this difference.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
How do I assert my exception message with JUnit Test ...
If my test method throws a checked exception and if I want to assert the message along with the exception, is there a...
Read more >Testing the wording of an Exception message
The main point of testing the exception message content is to make sure the right exception is thrown. There may be multiple reasons...
Read more >JUnit Test Exception Examples - How to assert an exception is ...
1. Test Exception in JUnit 5 - using assertThrows() method ... You put the code that can throw exception in the execute() method...
Read more >JUnit Assert Exception - JUnit 5 and JUnit 4 - DigitalOcean
We can test expected exceptions using JUnit 5 assertThrows assertion. This JUnit assertion method returns the thrown exception, so we can use it ......
Read more >Java: how to assert exception messages with JUnit 4 - LinkedIn
Introduction. It's easy to write a unit test to check if a certain exception is thrown, like this: @Test(expected = IndexOutOfBoundsException.
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
If we do implement checks for the presence of error messages, I think we should definitely add something about it to the README insert so that it’s clear that we’re expecting them (and to encourage people to make them meaningful).
Exception types are controlled by the test-suite, so there’s not really much problem on the learner side, but we should try to have some consistency between the test-suites. We could create something along the lines of the Choosing Exceptions to Raise doc
pandas
has to give everyone something to refer to.For future record, here is the proper way to handle exception testing in this repository:
Edit: if Python 2.7 is no longer supported, the above snippet may be simplified to the following: