Java 我应该使用哪些 Maven 工件来导入 PowerMock?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18645465/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Which Maven artifacts should I use to import PowerMock?
提问by user86834
What jars do I need to add to my pom.xml
to get PowerMock working with Mockito? I have the following dependencies:
我需要添加哪些 jarspom.xml
才能让 PowerMock 与 Mockito 一起工作?我有以下依赖项:
<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?
但是当我@PrepareForTest
在类级别添加注释时,Eclipse 找不到它,但它可以找到PowerMockito
. 我错过了什么罐子?
回答by Jeff Bowman
According to the Mockito_Mavenpage on the PowerMock wiki, use this:
根据PowerMock wiki 上的Mockito_Maven页面,使用:
<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
.
powermock-api-support
似乎是“仅限实用程序类”,您仍然需要powermock-module-junit4
.
回答by l3k
You are writting:
你在写:
@PrepareForTest(Class.class);
Instead of:
代替:
@PrepareForTest(Class.class)
I had exactly the same issue and solved it that way.
我遇到了完全相同的问题并以这种方式解决了它。
回答by javaPlease42
Make sure you have this import:
确保你有这个导入:
import org.powermock.core.classloader.annotations.PrepareForTest;
This jar has it:
这个罐子里有:
回答by Jai Krishnan
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.
除了powermock-module-junit4和powermock-api-mockito 依赖项之外,下载 Mockito 依赖项 zip 文件。直接在您的项目中添加该 jars 它应该可以工作并相应地配置您的 pom。