Vscode Java测试Junit
作者:互联网
Vscode Java测试Junit
安装插件 Extension Pack for Java
下载官方Jar包
创建Java工程
F1 -> Java 创建工程 -> No build tools
添加Jar包 -> lib
新建文件测试 Calculate -> src
被测试文件Calculate.java
public class Calculate {
public int add(int a,int b){
return a+b;
}
public int substract(int a , int b){
return a-b;
}
public int cheng(int a,int b){
return a*b;
}
public int chu(int a, int b){
return a/b;
}
}
测试文件CalculateTest.java
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class CalculateTest {
@Test
public void testAdd(){
assertEquals(6,new Calculate().add(3, 3));
}
@Test
public void testsubstract(){
assertEquals(2,new Calculate().substract(5, 3));
}
@Test
public void testcheng(){
assertEquals(15,new Calculate().cheng(5, 3));
}
@Test
public void testchu(){
assertEquals(2,new Calculate().chu(6, 3));
}
}
测试
标签:Java,Calculate,Vscode,assertEquals,public,int,Test,Junit 来源: https://www.cnblogs.com/Poppings/p/15490684.html