Expected Exceptions from JUnit
Use JUnit’s expected exceptions sparingly, from the JOOQ blog, says not to use JUnit‘s “expected exceptions” feature. (Or, more accurately, to use it “sparingly.”) It’s good advice, but it’s also largely limited to JUnit (with one main exception). What they’re addressing is the transition from this pattern: @Test public void testValueOfIntInvalid() { try { ubyte((UByte.MIN_VALUE) - 1); fail(); } catch (NumberFormatException e) {} } To this pattern: @Test(expected = NumberFormatException.class) public void testValueOfShortInvalidCase1...
Jan 21, 2016 — 4 minute(s) read