eclipse 找不到导入的 org.mockito.Mock
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36469859/
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
The import org.mockito.Mock cannot be found
提问by lukegjpotter
I am experiencing a problem I hope you can help with.
我遇到了一个问题,希望你能帮忙。
I want to use Mockito in my Spring Boot w/Gradle project, but STS cannot resolve the dependancy.
我想在我的 Spring Boot w/Gradle 项目中使用 Mockito,但 STS 无法解决依赖关系。
I have the following in my build.gradle
file;
我的build.gradle
文件中有以下内容;
repositories { jcenter() }
dependencies { testCompile('org.mockito:mockito-core:1.+') }
When I do a ./gradlew --info build
I can see that it is resolving Mockito:
当我执行 a 时,./gradlew --info build
我可以看到它正在解析 Mockito:
Resolved versions: {org.mockito:mockito-core=1.+}
Using version '1.+' for dependency 'org.mockito:mockito-core:1.+'
Using version '1.+' for dependency 'org.mockito:mockito-core:1.10.19'
After a ./gradlew cleanEclipse eclipse
it is in my STS Project's Build Path
之后./gradlew cleanEclipse eclipse
它在我的 STS 项目的构建路径中
My Code File is showing the following message:
我的代码文件显示以下消息:
I have another project, setup in exactly the same way and it is working fine.
我有另一个项目,以完全相同的方式设置,并且工作正常。
Please help me out guys, Luke.
请帮帮我,卢克。
回答by
Use with a static import:
与静态导入一起使用:
import static org.mockito.Mockito.when; ...or...
import static org.mockito.Mockito.*;