java 在 IntelliJ 中使用 mockito
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16114262/
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
using mockito with IntelliJ
提问by Ghassan Karwchan
I am new to Java, and my background mainly in .NET. I am trying to use mockito in a java project in IntelliJ. I am trying to follow this simple example:
我是 Java 新手,我的背景主要是 .NET。我正在尝试在 IntelliJ 的 Java 项目中使用 mockito。我试图遵循这个简单的例子:
http://code.google.com/p/mockito/
http://code.google.com/p/mockito/
so, I added the library mockito-all-1.9.5.jar to the folder c:\{my app path}\web\app\WEB-INF\lib
所以,我将库 mockito-all-1.9.5.jar 添加到文件夹 c:\{my app path}\web\app\WEB-INF\lib
and I added in IntelliJ using Project Structure and then Libraries.
然后我使用 Project Structure 和 Libraries 添加到 IntelliJ 中。
and I created a test class and add the following
我创建了一个测试类并添加以下内容
import static org.mockito.Mockito.*; and I am getting this error:
导入静态 org.mockito.Mockito.*; 我收到此错误:
"static imports are not supported at this language level"
“此语言级别不支持静态导入”
回答by JB Nizet
Under File - Project structure - Project, make sure to have the project language level set to at least 5.0. (I would expect 6.0 or 7.0 now). Static imports are indeed supported only since Java 5.
在File - Project structure - Project 下,确保将项目语言级别设置为至少 5.0。(我现在期望 6.0 或 7.0)。确实只有从 Java 5 开始才支持静态导入。
Also, Mockito is used only in tests, and has thus no reason to be part of the deployed libraries of the webapp. It should thus not be under WEB-INF/lib.
此外,Mockito 仅用于测试,因此没有理由成为 web 应用程序部署库的一部分。因此它不应该在 WEB-INF/lib 下。
回答by Andrew Mackenzie
If your question was about using Mockito with Java on Android, then note that you also need to include the following two Libraries:
如果您的问题是关于在 Android 上使用 Mockito 和 Java,那么请注意,您还需要包含以下两个库:
dexmaker-1.0.jar dexmaker-mockito-1.0.jar
dexmaker-1.0.jar dexmaker-mockito-1.0.jar
to allow Mockito to work with the Dalvik JVM in Android.
允许 Mockito 与 Android 中的 Dalvik JVM 一起工作。