I\'ve got the following test:
@Test(expected = IllegalStateException.class)
public void testKey() {
int key = 1;
this.finder(key);
}
<
This looks correct to me.
Check your assumptions. Are you sure it throws the exception? If what you say is true, removing the expected from the annotation should make it fail.
I'd be stepping through the code with a debugger to see what's going on. I'll assume you have an IDE that will do so, like IntelliJ.
i tried this one, and work perfectly as expected.
public class SampleClassTest {
@Test(expected = ArithmeticException.class )
public void lost(){
this.lost(0);
}
private void lost(int i) throws ArithmeticException {
System.out.println(3/i);
}
}
also ensure that junit4 is added as dependancy, @ (annotations) are new feature in junit 4.