我已经提出要求依赖
testCompile 'org.mockito:mockito-core:1.10.19'
然后我将测试代码放到/src/test/java/
目录
然后我尝试启动这样的测试
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
public class PresenterActivityAcceptNotAcceptTest {
@Test
public void emailValidator_CorrectEmailSimple_ReturnsTrue() {
boolean dd = true;
assertThat(dd, is(true));
}
它工作正常,但如果我添加与Mock
lib
例如@RunWith
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@RunWith(MockitoJUnitRunner.class)
public class PresenterActivityAcceptNotAcceptTest {
@Test
public void emailValidator_CorrectEmailSimple_ReturnsTrue() {
boolean dd = true;
assertThat(dd, is(true));
}
我收到了这样的错误
Error:Execution failed for task ':Application:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Error:(10, 10) error: cannot find symbol class MockitoJUnitRunner
Error:(5, 27) error: package org.mockito.runners does not exist
/home/aleksey/Downloads/NTZ/FittingRoom/Application/src/test/java/com/fittingroom/newtimezone/presenters/PresenterActivityAcceptNotAcceptTest.java
我做错了什么?
如果我伪造某事可以随意提问
提前致谢!
答案 0 :(得分:4)
看起来Gradle没有做到这一点。 手动添加罐子可能会解决问题。 How to Download and Install jar go here .
并下载mockito使用此链接
https://mvnrepository.com/artifact/org.mockito/mockito-core/1.10.19
答案 1 :(得分:1)
答案 2 :(得分:1)
遇到了同样的问题。尝试实现developer.android文档示例。
已通过在build.gradle中将org.mockito版本更改为最新版本来解决:
dependencies {
testImplementation 'org.mockito:mockito-core:2.28.2'
}
答案 3 :(得分:0)
当我尝试在instrumentalTests
中编写src/androidTest/java/
时也遇到了此异常,但是默认情况下,Mockito的依赖范围设置为单元测试实现(您可以在File
=> Project Structure
=> Modules
=> Dependencies
)。我刚刚将此参数更改为测试实施,并且可以正常工作!
答案 4 :(得分:-1)