dropwizard + Powermock + Mockito + Maven build error with ClassNotFoundException “ThreadSafeMockingProgress”

对着背影说爱祢 提交于 2019-12-12 03:37:20

问题


For testing static method I am using Power mock and pom.xml entry for this is

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>1.8.5</version>
        <scope>test</scope>
    </dependency>

          <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-api-mockito</artifactId>
        <version>1.4.9</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-module-junit4</artifactId>
        <version>1.4.9</version>
        <scope>test</scope>
    </dependency>

`

I am running test cases from command prompt which gives me error like

java.lang.RuntimeException: java.lang.ClassNotFoundException: org.mockito.internal.progress.ThreadSafeMockingProgress
at org.powermock.api.support.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:52)

However from Intellij ide, if I run the all test cases(right click on the project + Run "All tests") it works absolutely fine. Does anybody have any idea on this issue?


回答1:


when you are defining the power mock jars in pom.xml, you don't need to explicitly define dependent jars as incompatible versions may come in the classpath. Use below two versions & remove mockito dependency in you pom.

<dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-module-junit4</artifactId>
        <version>1.5.4</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-api-mockito</artifactId>
        <version>1.5.4</version>
        <scope>test</scope>
    </dependency>


来源:https://stackoverflow.com/questions/31717931/dropwizard-powermock-mockito-maven-build-error-with-classnotfoundexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!