Java之在IDEA中添加junit包做单元测试

1.junit资源下载

  1. 我这里使用的是IDEA2018.2.8版本,使用的junit-4.10.jar。
  2. junit-4.10.jar下载链接
    链接:https://pan.baidu.com/s/1LN18YKLSd1UxB0ihZO6sAw
    提取码:umio

2.IDEA中如何添加junit包

  1. 在IDEA中选择File-Project Structure(或直接使用快捷键ctrl+alt+shift+s打开),点击最右边的+号,选择jars or directories。
    在这里插入图片描述
  2. 在这里找到自己的jar包路径点击OK即可。
    在这里插入图片描述

3.基本使用代码

  1. 测试的类中导入junit包,类名一般是以Test开头。在类中写的方法之前加上“@Test"即可,IDEA中运行这块的代码即可。
import org.junit.Test;
public class TestJunit {
@Test
    public void test(){
        System.out.println("junit test");//输出:unit test
    }
}
发布了7 篇原创文章 · 获赞 16 · 访问量 2905

猜你喜欢

转载自blog.csdn.net/qq_45920729/article/details/104403165