Thursday, March 5, 2015

YAJUEHP - Yet Another JUnit Exception-Handling Post . . . *yawn*

I can't imagine anyone will find this useful when it is so tiresome to me, but after a jaunt in UI Testing purgatory I had to go back and test some plain old library code, but this time with a new twist.  I have been using the rather awesome ExpectedException class with nice results.  The Code Under Test in this case, however, threw InvocationTargetException's with wrapped cause's which made that approach too brittle.  I found this nice post about it which solved my issue:

JUNIT EXPECTEDEXCEPTION RULE: BEYOND BASICS

Toward the bottom there is a nice discussion of verifying causes.  I found another article he wrote comparing various exception strategies in JUnit here:

6 WAYS OF HANDLING EXCEPTIONS IN JUNIT. WHICH ONE TO CHOOSE?

I thought these were pretty handy - hopefully someone else will as well.

No comments:

Post a Comment