测试概述
Junit使用步骤
public class Calculator {
public static int method(int a, int b) {
return a + b;
}
}
import com.learning.demo03.Calculator;
import org.junit.Assert;
import org.junit.Test;
public class NewTest {
@Test
public void method01(){
Calculator cal = new Calculator();
int method = cal.method(10, 20);
System.out.println(method);
Assert.assertEquals(-1,method);
}
}
@Before&@After
public class Calculator {
public static int method(int a, int b) {
return a + b;
}
}
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class NewTest {
@Before
public void init() {
System.out.println("init...");
}
@After
public void close() {
System.out.println("close");
}
@Test
public void method01(){
Calculator cal = new Calculator();
int method = cal.method(10, 20);
System.out.println(method);
Assert.assertEquals(-1,method);
}
}