Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#16 Unit tests should use @Test{Expected=FooException.class}

open
nobody
None
1
2013-03-24
2013-03-24
Egon Willighagen
No

Instead of using code like below to test that an exception is thrown:

public void testSomething() {
try {
int[] results = match("[G]", "CCN");
Assert.fail("Should throw an exception if G is not followed by a number");
} catch (IllegalArgumentException pe) {
Assert.assertTrue(true);
}
}

... the unit test should use the JUnit4 @Test approach, like:

@Test(expected=IllegalArgumentException.class)
public void testSomething() {
int[] results = match("[G]", "CCN");
}

This happens at several places in the current 'master' branch.

Discussion