Vscode Java测试Junit
Vscode Java测试Junit
安装插件 Extension Pack for Java![](https://raw.githubusercontent.com/HeisensOppings/Img/main/img/Embedded/Java/java1.png)
下载官方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));
}
}