import org.junit.Assert; import org.junit.Test; public class CalculatorTest { @Test(expected = ArithmeticException.class) public void divisionWithException() { int numerator = 10; int denominator = 0; int result = numerator / denominator; } @Test public void testAddition() { int operand1 = 5; int operand2 = 10; Calculator calculator = new Calculator(); int result = calculator.add(operand1, operand2); Assert.assertEquals(15, result); } } <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> <scope>test</scope> </dependency> </dependencies>


上一篇:
下一篇:
切换中文