Which Maven artifacts should I use to import PowerMock?

user86834 picture user86834 · Sep 5, 2013 · Viewed 66.5k times · Source

What jars do I need to add to my pom.xml to get PowerMock working with Mockito? I have the following dependencies:

<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-all</artifactId>
    <version>1.9.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.powermock</groupId>
    <artifactId>powermock-api-mockito</artifactId>
    <version>1.4.11</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.powermock</groupId>
    <artifactId>powermock-api-support</artifactId>
    <version>1.4.11</version>
    <scope>test</scope>
 </dependency>

but when I add the @PrepareForTest annotation at class level, Eclipse cannot find it, but it can find PowerMockito. What jar am I missing?

Answer

Jeff Bowman picture Jeff Bowman · Sep 5, 2013

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.