用junit 4给java小问题测试问题
求助, 给这个简单的java程序的 加减乘除function做junit 4的测试。 应该怎么写呢? 要求加减乘除都测试。 万分感谢!!!!!计算机java程序代码:
public class Calculator {
public static int add(int number1, int number2) {
return number1 + number2;
}
public static int sub(int number1, int number2) {
return number1 - number2;
}
public static int mul(int number1, int number2) {
return number1 * number2;
}
// Integer divide. Return a truncated int.
public static int divInt(int number1, int number2) {
if (number2 == 0) {
throw new IllegalArgumentException("Cannot divide by 0!");
}
return number1 / number2;
}
// Real number divide. Return a double.
public static double divReal(int number1, int number2) {
if (number2 == 0) {
throw new IllegalArgumentException("Cannot divide by 0!");
}
return (double) number1 / number2;
}
}
-------------------
junit 4测试 模板:
import org.junit.Test;
import static org.junit.Assert.*;
public class CalculatorTest {
@Test
public void add() {
}
@Test
public void sub() {
}
@Test
public void mul() {
}
@Test
public void divInt() {
}
@Test
public void divReal() {
}
}