#junit

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...

4 minute(s) read

Junit 4 examples

There seems to be some repeated questions about using JUnit. So I made a short example using JUnit 4 with ant. First here is the directory structure of my files. build build/build.sh build/build.xml lib lib/hamcrest-core-1.3.jar lib/junit-4.11.jar src src/org src/org/javachannel src/org/javachannel/SimulatedSpring.java test test/org test/org/javachannel test/org/javachannel/SimulatedSpringTest.java The class I want...

4 minute(s) read