解决:java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing

  • 时间:
  • 浏览:
  • 来源:互联网

JUnit使用时报java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing错误

解决办法一、把测试依赖换成如下所示:

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.hamcrest</groupId>
                <artifactId>hamcrest-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- This will get hamcrest-core automatically -->
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-library</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>
</dependencies>

解决办法二:升级junit

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.8.1</version>
    <scope>test</scope>
</dependency>

本文链接http://www.dzjqx.cn/news/show-617205.html