JUnit引入junit-4.12.jar,单元测试报错:java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhoukikoo/article/details/80632056

版本问题:JUnit 4.11以上版本不再包含hamcrest的依赖包

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.

  • junit.jar: Includes the Hamcrest classes. The simple all-in-one solution to get started quickly.Starting with version 4.11, Hamcrest is no longer included in this jar.
  • junit-dep.jar: Only includes the JUnit classes but not Hamcrest. Lets you use a different Hamcrest version.

解决方式:

  • 回退到junit-4.10.jar
  • 添加hamcrest-core-1.3.jar

    • 既然用了junit-4.12.jar版本,那就再添加一个hamcrest-core-1.3.jar
  • 这里写图片描述
  • 这里写图片描述

猜你喜欢

转载自blog.csdn.net/zhoukikoo/article/details/80632056