IDEA 中配置junit

Junit4 主要用来执行java程序的单元测试:

1 安装junit4插件

    因为我安装过了,没有安装的再输入框搜索,然后安装就行

 IDEA 中配置junit

IDEA 中配置junit

 

2 选择默认使用Junit4

 IDEA 中配置junit

 

 

3 红框中的test去掉,变为“$entry.packageName”

 IDEA 中配置junit

4 新建一个普通的类,随便写点东西,然后光标在类名上点一下,然后“alt+insert”,根据图进行选择

  IDEA 中配置junit

 

 

5 可能会碰上这样的错误

 IDEA 中配置junit

 

6 进入junit官网,进入junit4

 IDEA 中配置junit

7 点击“download and install”

 IDEA 中配置junit

 

8 可以通过第一种方式,下载好jar,然后导入到项目,也可以通过第二种方式Maven来直接构建到项目中

 IDEA 中配置junit

9 如果你用maven,它会不仅仅下载junit4,还会下载hamcrest作为juit4的依赖

 IDEA 中配置junit

10 引入jar包:勾选jar包,选择compile,点击apply,点击ok

 IDEA 中配置junit

 

 

11 右键,选择具体运行的类

 IDEA 中配置junit

 

Junit运行结束!