Testing Exceptions in JUnit

20 views
Skip to first unread message

Jon Dickinson

unread,
Dec 19, 2008, 11:32:52 AM12/19/08
to Test-Driven...@googlegroups.com
I posted a blog entry about testing exceptions in JUnit recently which gives an alternative to using the try{} catch{} structure when testing for exceptions where the @Test( expected = SomeException.class ) annotation is not appropriate: http://blog.jonmdickinson.com/2008/12/testing-exceptions-in-junit.html . 

As mentioned in my post, this approach was inspired by the use of Groovy closures when testing exceptions. 

I was wondering if anyone knew whether this approach was available in any JUnit extension projects or other Java based testing frameworks? I couldn't find it being used anywhere else. 

Also, I'd like some feedback as to whether people like the look of this approach. I've had mixed reactions. Some like the fact it removes the try{} catch{} notation and the manual repetition that goes with it, others find it harder to follow.

Thanks,

Jon Dickinson

wayneseymour

unread,
Nov 17, 2011, 8:56:38 AM11/17/11
to test-driven...@googlegroups.com, Test-Driven...@googlegroups.com
I like what you've done.  I wonder if newer versions of Java in general, and JUnit in particular may assist in cleaning up the syntax.
Reply all
Reply to author
Forward
0 new messages