Method 'initializationerror' not found.Opening the test classs JUnit4单元测试报错问题解决办法(图文详解)
不多说,直接上干货!
问题现象
今天使用JUnit 4进行单元测试时,测试程序一直运行不起来,报method initializationerror not found错误,如下:

问题分析
网上说版本不对,我试了试,还是有这个问题,后来才知道,缺少了jar包,除了引入junit-4.12.jar之外,还要引入2个依赖jar包:hamcrest-core-1.3.rc2.jar,hamcrest-library-1.3.rc2.jar,提供大家免费的下载链接:
三个汇总下载:
https://download.csdn.net/download/u010106732/10378280
变成 
导入这些jar包之后,问题游刃而解,是的,我承认自己也是JUnit新手
。
至于JUnit的jar包和hamcrest的jar包关系,下边我引用一位网友的几段话来解释解释:
junit和hamcrest是两个不同的框架,不同的东西。只不过是junit使用了hamcrest框架而已。
在junit上下载的junit的包解压开见下图:

刚下载的JUnit的jar包解压开的文件。
junit-4.10.jar :包含junit-dep-4.10.jar全部内容和必要的harmcres的包,
junit-4.10-src:是源代码,但不包含org.harmcres.*相关的源代码(在图中temp.hamcrest.source中)。
junit-dep-4.10.jar :是junit的包,不含harmcres的相关的类,import此包还需引入harmcres相关的包。
下载到关于hamcrest的相关的一系列的包(如果是java就下载jar的包)

hamcrest-all-1.3.ORC2.ajr:几乎包含所有的hamctest的类(没有验证过)。
hamcrest-core-1.3.ORC2.jar:hamcrest的核心包,使用hamcrest框架必须引入的包。(junit官方给的包就包含了该包)
hamcrest-library-1.3.ORC2.jar:包含各种断言,补充hamcrest core包中的断言。
使用是导入包的方案:junit.jar + hamcrest-core.jar + hamcrest-library.jar
或者是:junit-dep.ajr+hancrest-all.jar
这两种导入方法虽然尽量避免了导入重复的包,但使用时还是遇到了冲突。查看包中各类和文档后发现有些类(例如:断言is())同时出现在了org.hamcrest.Mathchers和org.hamcrest.core中,则在用到时候引入的时候需要注意。
同时,大家可以关注我的个人博客:
http://www.cnblogs.com/zlslch/ 和 http://www.cnblogs.com/lchzls/ http://www.cnblogs.com/sunnyDream/
详情请见:http://www.cnblogs.com/zlslch/p/7473861.html
人生苦短,我愿分享。本公众号将秉持活到老学到老学习无休止的交流分享开源精神,汇聚于互联网和个人学习工作的精华干货知识,一切来于互联网,反馈回互联网。
目前研究领域:大数据、机器学习、深度学习、人工智能、数据挖掘、数据分析。 语言涉及:Java、Scala、Python、Shell、Linux等 。同时还涉及平常所使用的手机、电脑和互联网上的使用技巧、问题和实用软件。 只要你一直关注和呆在群里,每天必须有收获
对应本平台的讨论和答疑QQ群:大数据和人工智能躺过的坑(总群)(161156071)






Method 'initializationerror' not found.Opening the test classs JUnit4单元测试报错问题解决办法(图文详解)的更多相关文章
- 【JUnit 报错】 method initializationerror not found:JUnit4单元测试报错问题
今天是用JUnit测试一段代码,报错method initializationerror not found::出现如下问题: 双击这个就显示出现如下的错误: 查询网上,说是junit版本的问题: 那 ...
- ambari-server启动报错500 status code received on GET method for API:/api/v1/stacks/HDP/versions/2.4/recommendations Error message : Server Error解决办法(图文详解)
问题详情 来源是,我在Ambari集群里,安装Hue. 给Ambari集群里安装可视化分析利器工具Hue步骤(图文详解 所遇到的这个问题. 然后,去ambari-server的log日志,查看,如下 ...
- 全网最详细的启动zkfc进程时,出现INFO zookeeper.ClientCnxn: Opening socket connection to server***/192.168.80.151:2181. Will not attempt to authenticate using SASL (unknown error)解决办法(图文详解)
不多说,直接上干货! at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:) at org ...
- maven创建web报错Cannot read lifecycle mapping metadata for artifact org.apache.maven.plugins:maven-compiler-plugin:maven-compiler-plugin:3.5.1:runtime Cause: error in opening zip file
Cannot read lifecycle mapping metadata for artifact org.apache.maven.plugins:maven-compiler-plugin:m ...
- 【踩坑】报错 non-static method xxx() cannot be referenced from a static context
今天测试代码时遇到 Error:(6, 55) java: non-static method sayGoodbye() cannot be referenced from a static cont ...
- method initializationerror not found:JUnit4单元測试报错问题
今天使用JUnit 4进行单元測试时,測试程序一直执行不起来,报method initializationerror not found错误.例如以下: 网上说版本 ...
- Tomcat启动报错:org.apache.catalina.LifecycleException: Failed to start component...java.util.zip.ZipException: error in opening zip file
1.项目环境 IntelliJ IDEA2018.1.6 apache-tomcat-8.0.53 基于springboot开发的项目 maven3.5.3 2.出现问题 从svn同步下项目 启动to ...
- 【POI】解析xls报错:java.util.zip.ZipException: error in opening zip file
今天使用POI解析XLS,报错如下: Servlet.service() for servlet [rest] in context with path [/cetBrand] threw excep ...
- 【Flink】flink执行jar报错:java.io.IOException: Error opening the Input Split file 或者 java.io.FileNotFoundException
报错内容 flink执行jar时,报如下错误: org.apache.flink.client.program.ProgramInvocationException: Job failed. (Job ...
随机推荐
- Arria10调试问题集之——480转成270中DDR4 IP重新生成的问题
在把FPGA器件从480修改成270时DDR4报错: Error (16383): Silicon revision parameter for the following EMIF/PHYLite ...
- C++ char, unsigned char, signed char
C语言中的 char, unsigned char, signed char 一.他们是什么? signed char是有符号的,但是unsigned char没有符号,两者在存储上没有任何区别都是8 ...
- HTTP 错误 500.XX - Internal Server Error 解决办法
HTTP 错误 500.19 - Internal Server Error 无法访问请求的页面,因为该页的相关配置数据无效. 详细错误信息 模块 IIS Web Core 通知 未知 处理程序 尚未 ...
- spring ioc beanfactory 关系图
spring security类关系图 mybatis-spring源码解析类关系图 Spring与Mybatis整合的MapperScannerConfigurer处理过程源码分析 转: sprin ...
- 重建控制文件ORA-12720
重建过程出错:ORA-01503: CREATE CONTROLFILE failedORA-12720: operation requires database is in EXCLUSIVE mo ...
- bzoj2893(费用流)
先缩点,然后拆点,其实是很经典的一种操作,把不好做的点拆成边,然后我一开始想的是网络流,答案当然是增广次数, 但可以发现跑网络流的话不同的跑法增广次数不一样,不太好找最小的.我们可以换一种神奇的思路, ...
- 设置customer_id
update t_user_identification u set u.customer_id = (select c.customer_id from t_customer c from t_us ...
- python常用算法题
一: #计算平均数,中位数和众数 #coding:utf-8 #计算平均数,中位数和众数 import random lst = [random.randint(0,10) for i in rang ...
- bootstrap 警告框单个删除
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...
- uva 10918 - Tri Tiling(规律)
题目链接:uva 10918 - Tri Tiling 题目大意:给出n,计算用1*2的瓷砖有多少种方法铺满3*n的地方. 解题思路:和uva 10359 - Tiling有点相似,不过难度会比较大, ...