标签:允许 err java单元测试 pre 应该 -- rdo 很多 maven
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
import org.junit.Assert;
/**
* @author wzm
* @version 1.0.0
* @date 2020/1/24 15:25
**/
public class MyTest {
private static void test(int x) {
int c = 10 + 20;
int a = 12 * 100 / x;
Assert.assertTrue("expected a == c ,but a != c", a == c);
System.out.println("a == c");
}
public static void main(String[] args) {
int x = 10;
test(x);
}
}
报错如下:
import org.junit.Assert;
/**
* @author wzm
* @version 1.0.0
* @date 2020/1/24 15:25
**/
public class MyTest {
private static void test(int x) {
int c = 10 + 20;
int a = 12 * 100 / x;
Assert.assertTrue("expected a == c ,but a != c", a == c);
System.out.println("a == c");
}
public static void main(String[] args) {
int x = 40;
test(x);
}
}
运行结果:
assertTrue
assertFalse
assertEquals
assertNotEquals
assertArrayEquals
...
import org.junit.*;
public class MyTestTest {
public MyTestTest() {
System.out.println("--new MyTestTest()");
}
@BeforeClass
public static void setUpBeforeClass() {
System.out.println("--BeforeClass()");
}
@AfterClass
public static void tearDownAfterClass() {
System.out.println("--AfterClass()");
}
@Before
public void setUp() {
System.out.println("--Before()");
}
@After
public void tearDown() {
System.out.println("--After()");
}
@Test
public void testA() {
System.out.println("--testA()");
}
@Test
public void testB() {
System.out.println("--testB()");
}
@Test
public void testC() {
System.out.println("--testC()");
}
}
@Test(timeout = 1000)
public void testA() {
System.out.println("--testA()");
}
@Test(expected = ArithmeticException.class)
public void testException() {
int i = 1 / 0;
}
@Test(expected = ArithmeticException.class)
public void testException() {
int i = 1 / 1;
}
java.lang.AssertionError: Expected exception: java.lang.ArithmeticException
标签:允许 err java单元测试 pre 应该 -- rdo 很多 maven
原文地址:https://www.cnblogs.com/jockming/p/12232352.html