Menu

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

open
nobody
None
1
2013-03-24
2013-03-24
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


Log in to post a comment.