Kaloyan Roussev
Kaloyan Roussev

Reputation: 14711

Android Studio does not recognize Mockito

Here is my test class:

import org.junit.Before;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class OrmLiteTest {

    @Mock
    Context mMockContext;

    @Before
    public void setup() {
        OrmLiteDatabaseHelper databaseHelper = new OrmLiteDatabaseHelper(mMockContext);
    }

}

Everything Mockito-related is colored in red and when alt+entering it, there is no "import class" option.

My test class is located in the

com.example.myapp
com.example.myapp(androidTest) folder

This is part of my gradle.build file:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:1.10.19'
}
repositories {
    mavenCentral()
    maven { url 'https://maven.fabric.io/public' }
    jcenter()
}

Upvotes: 0

Views: 1991

Answers (1)

Héctor
Héctor

Reputation: 26084

If you want pure unit tests, instead of instrumentation Android tests, you have to create your test classes under src/test/java directory and change test artifact to 'Unit Tests' in Android Studio (in Build Variants tool window).

Upvotes: 6

Related Questions