IDEA手动添加junit4时出现的问题与解决方法

 更新时间:2021年3月20日 15:00  点击:2186

当我写@Test注解时,一直报错

 

后来百度是缺少junit4的包

手动添加junit4包

具体查看是在左上角 file–>project structure

点击进来以后选择modules,再点击当前的项目JDBC,就可以看到当前模块的一些依赖库,此时是没有导入junit4的。

此时点击右边加号,点击2.library,再点击Java,选择IDEA安装目录,在lib文件夹中找到junit-4.12

然后应用,此时@Test注解不再报错,但是运行时出现错误

查询官网:

查官网:

JUnit now uses the latest version of Hamcrest. Thus, you can use all the available matchers and benefit from an improved assertThat which will now print the mismatch description from the matcher when an assertion fails.

所以出现这个错误的原因是:还有一个hamcrest-core-1.3.jar包未导入

重复上述操作,把hamcrest-core-1.3.jar导入项目

此时就可以愉快的进行测试了

总结

到此这篇关于IDEA手动添加junit4时出现的问题与解决方法的文章就介绍到这了,更多相关IDEA手动添加junit4内容请搜索猪先飞以前的文章或继续浏览下面的相关文章希望大家以后多多支持猪先飞!

[!--infotagslink--]

相关文章