package com.common;
import org.junit.*;
import static org.junit.Assert.*;
import java.util.*;
public class JunitTest{
@BeforeClass
public void beforeClass(){
System.out.println("@BeforeClass - oneTimeSetUp");
}
@AfterClass
public void afterClass(){
System.out.println("@AfterClass - oneTimeSetUp");
}
@Before
public void before(){
System.out.println("@Before - oneTimeSetUp");
}
@After
public void after(){
System.out.println("@After - oneTimeSetUp");
}
@Ignore("Not Ready to Run")
@Test(expected = ArithmeticException.class)
public void Test1(){
System.out.println("@Test1 - oneTimeSetUp");
}
@Test
public void Test2(){
System.out.println("@Test2 - oneTimeSetUp");
}
}
1.五个基本的anno
@BeforeClass //加载class之前
@AfterClass //加载class之后
@Before //每次运行test前
@After //每次运行test后
@Test
2.异常
@Test(expected = ArithmeticException.class)
3.忽略测试
@Ignore("Not Ready to Run")
4.时间规定
@Test(timeout = 1000)
5.运行test suit
@RunWith(Suite.class)
@Suite.SuiteClasses({
JunitTest1.class,
JunitTest2.class
})
public class JunitTest5 {
}
在JunitTest5运行时同时运行JunitTest1,JunitTest2