Which Maven artifacts should I use to import PowerMock?

回眸只為那壹抹淺笑 提交于 2019-12-03 05:50:17
Jeff Bowman

According to the Mockito_Maven page on the PowerMock wiki, use this:

<properties>
    <powermock.version>1.6.6</powermock.version>
</properties>
<dependencies>
   <dependency>
      <groupId>org.powermock</groupId>
      <artifactId>powermock-module-junit4</artifactId>
      <version>${powermock.version}</version>
      <scope>test</scope>
   </dependency>
   <dependency>
      <groupId>org.powermock</groupId>
      <artifactId>powermock-api-mockito</artifactId>
      <version>${powermock.version}</version>
      <scope>test</scope>
   </dependency>
</dependencies>

powermock-api-support seems to be "utility classes only", where you still need the core libraries provided in powermock-module-junit4.

Make sure you have this import:

import org.powermock.core.classloader.annotations.PrepareForTest;

This jar has it:

You are writting:

    @PrepareForTest(Class.class);

Instead of:

    @PrepareForTest(Class.class)

I had exactly the same issue and solved it that way.

Download the Mockito dependency zip file apart from your powermock-module-junit4 & powermock-api-mockito dependecies. Add that jars directly in your project it should work and configure your pom accordingly.

Power Mockito dependencies - All Jars

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