Method 'initializationerror' not found.Opening the test classs JUnit4单元测试报错问题解决办法(图文详解)

时间:2023-03-09 13:13:39
Method 'initializationerror' not found.Opening the test classs JUnit4单元测试报错问题解决办法(图文详解)

  不多说,直接上干货!

  问题现象

  今天使用JUnit 4进行单元测试时,测试程序一直运行不起来,报method initializationerror not found错误,如下:

Method 'initializationerror' not found.Opening the test classs JUnit4单元测试报错问题解决办法(图文详解)

  问题分析

  网上说版本不对,我试了试,还是有这个问题,后来才知道,缺少了jar包,除了引入junit-4.12.jar之外,还要引入2个依赖jar包:hamcrest-core-1.3.rc2.jar,hamcrest-library-1.3.rc2.jar,提供大家免费的下载链接:

  三个汇总下载:

https://download.****.net/download/u010106732/10378280

Method 'initializationerror' not found.Opening the test classs JUnit4单元测试报错问题解决办法(图文详解)    变成            Method 'initializationerror' not found.Opening the test classs JUnit4单元测试报错问题解决办法(图文详解)

  导入这些jar包之后,问题游刃而解,是的,我承认自己也是JUnit新手Method 'initializationerror' not found.Opening the test classs JUnit4单元测试报错问题解决办法(图文详解)

至于JUnit的jar包和hamcrest的jar包关系,下边我引用一位网友的几段话来解释解释:

junit和hamcrest是两个不同的框架,不同的东西。只不过是junit使用了hamcrest框架而已。

在junit上下载的junit的包解压开见下图:

Method 'initializationerror' not found.Opening the test classs JUnit4单元测试报错问题解决办法(图文详解)

Method 'initializationerror' not found.Opening the test classs JUnit4单元测试报错问题解决办法(图文详解)

刚下载的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的包)

Method 'initializationerror' not found.Opening the test classs JUnit4单元测试报错问题解决办法(图文详解)

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单元测试报错问题解决办法(图文详解)Method 'initializationerror' not found.Opening the test classs JUnit4单元测试报错问题解决办法(图文详解)Method 'initializationerror' not found.Opening the test classs JUnit4单元测试报错问题解决办法(图文详解)Method 'initializationerror' not found.Opening the test classs JUnit4单元测试报错问题解决办法(图文详解)Method 'initializationerror' not found.Opening the test classs JUnit4单元测试报错问题解决办法(图文详解) 

Method 'initializationerror' not found.Opening the test classs JUnit4单元测试报错问题解决办法(图文详解)

Method 'initializationerror' not found.Opening the test classs JUnit4单元测试报错问题解决办法(图文详解)

Method 'initializationerror' not found.Opening the test classs JUnit4单元测试报错问题解决办法(图文详解)