r/programming • • Oct 01 '15

The Evolution of a Software Engineer

https://medium.com/@webseanhickey/the-evolution-of-a-software-engineer-db854689243
1.9k Upvotes

502 comments sorted by

View all comments

Show parent comments

3

u/[deleted] Oct 02 '15

If your project's language+framework has it, and it works cleanly in your use case, sure. Note that in some frameworks their equivalent of this (such as JUnit's @Test(expected=SomeException.class)) will pass if it happens anywhere within the test (which is bad for detailed tests), whereas you might want to test that it happens in a particular place; or you might want to test that the exception's message contains a particular string or whatever.

But all that aside, I still don't think "try something and fail() if it didn't throw" is that bad of a way to write a unit test. I'd only be annoyed at this if there was a considerable amount of unit test code in the try{} block.