public class MyMathTest {
@Test
public void testAddition() {
MyMath math = new MyMath();
int result = math.add(2, 3);
assertEquals(5, result);
}
@Test
public void testSubtraction() {
MyMath math = new MyMath();
int result = math.subtract(5, 2);
assertEquals(3, result);
}
}
上述代码中,我们使用@Test注解标注了两个测试方法testAddition()和testSubtraction()。在每个测试方法中,我们创建了被测试的对象,调用相应的方法,并使用断言语句来验证代码的正确性。