依赖包 junit-4.7.jar
@Test 注解
package junit;
import org.junit.Test;
/**
* 选中add,右键运行 add()
*/
public class Demo1 {
@Test
public void add(){
int a = 10;
int b = 13;
int sum = a + b;
System.out.println(sum);
}
}
@Before @After注解,在测试函数前后执行
package junit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* 选中add,右键运行 add()
*/
public class Demo2 {
@Before
public void before(){
System.out.println("before");
}
@Test
public void add(){
int a = 10;
int b = 13;
int sum = a + b;
System.out.println(sum);
}
@After
public void after(){
System.out.println("after");
}
}