I am practicing with JUnit, this is the simple method I want to test
public float divide(int a, int b){
return (float)a/(float)b;
}
This is the test (Maths is just a custom class of mine containing that method):
@Test(expected = ArithmeticException.class )
public void divideByZeroShouldBeDetected(){
Maths m = new Maths();
m.divide(2,0);
}
Anyway running this test results into a fail...
edit: ok just checked something "strange", this code actually gives me the exception:
float c = 2/0;
anyway this one:
m.divide(2,0);
gives me
Infinity
and that's the reason why the test fails. So..how to test this behaviour in Junit?