不多说,直接上干货!

  问题现象

  今天使用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单元测试报错问题解决办法(图文详解)的更多相关文章

  1. 【JUnit 报错】 method initializationerror not found:JUnit4单元测试报错问题

    今天是用JUnit测试一段代码,报错method initializationerror not found::出现如下问题: 双击这个就显示出现如下的错误: 查询网上,说是junit版本的问题: 那 ...

  2. 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日志,查看,如下 ...

  3. 全网最详细的启动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 ...

  4. 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 ...

  5. 【踩坑】报错 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 ...

  6. method initializationerror not found:JUnit4单元測试报错问题

           今天使用JUnit 4进行单元測试时,測试程序一直执行不起来,报method initializationerror not found错误.例如以下:            网上说版本 ...

  7. 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 ...

  8. 【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 ...

  9. 【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 ...

随机推荐

  1. 反射List<M> To DataTable|反射IList To DataTable|反射 DataTable To List<M>

    将DataTable集合反射获取 List<M> /// <summary> /// 根据DataTable集合反射获取 List<M> /// </summ ...

  2. Linux远程批量工具mooon_ssh和mooon_upload使用示例

    目录 目录 1 1. 前言 1 2. 批量执行命令工具:mooon_ssh 2 3. 批量上传文件工具:mooon_upload 2 4. 使用示例 3 4.1. 使用示例1:上传/etc/hosts ...

  3. C#-vs2012学习笔记-惊奇于vs的强大和便利

    网站常用功能自动完成,包括网页和数据库.

  4. spring整合redis之hello

    1.pom.xml文件 <dependencies> <!-- spring核心包 --> <dependency> <groupId>org.spri ...

  5. html5打开摄像头并用canvas模拟拍照 - 转

    <video id="video" width="640" height="480" autoplay></video&g ...

  6. 微信小程序-button组件

    主要属性: 注:button-hover 默认为{background-color: rgba(0, 0, 0, 0.1); opacity: 0.7;} 效果图: ml: <!--默认的but ...

  7. TryEnterCriticalSection___Delphi

    VOID EnterCriticalSection:非阻塞函数.将当前线程对指定临界区的引用计数减1:在使用计数变为零时,另一等待此临界区的一个线程将被唤醒. BOOL TryEnterCritica ...

  8. lnmp mysql添加用户命令

    cd /usr/local/mysql/bin/grant all privileges on *.* to 'root'@'%' identified by '12345678';flush pri ...

  9. 附加题:将四则运算源代码上传到Github账户上

    1.创建仓库用于存储管理本地文件 2.远程添加github上的Blog仓库. 3.获取github中Blog仓库的地址. 4.在Add Remote窗口中填写名字.Location. 5.将本地文件通 ...

  10. [NewCode 6] 重建二叉树

    题目描述 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7, ...