public static Grade fromPercentage(int g) throws IllegalArgumentException {
if (g >= 79 && g <= 100) {
return new Grade(1);
}
if (g >= 76 && g <= 78) {
return new Grade(2);
}
if (g >= 73 && g <= 75) {
return new Grade(3);
}
if (g == -1) {
return new Grade(20);
}
throw new IllegalArgumentException();
}
如何为此if
语句编写参数化测试。
@Test
public void frmPerc2() {
Grade perc2 = Grade.fromPercentage(76);
assertEquals(perc2, new Grade(2));
}
目前我正在为junit编写这种方式,但是assertEquals会出错。