Espresso test cannot see class under test


#1

I have some Espresso tests in Kotlin, and they run fine in Android Studio (the test class is annotated and run by AndroidJUnit4 runner), but running the Gradle task “assembleDebugAndroidTest" from terminal leads to a failure of finding my main classes and packages (classes used in the tests). It throws Unresolved Reference and Cannot access class. Check your module classpath for missing or conflicting dependencies errors.

I have added the file path of the tests to the sourceSets in my build script:

sourceSets {

    androidTest {
      java.srcDir 'src/functionalTests/java'
      java.srcDir 'src/functionalTests/kotlin'
    }

    test.java.srcDirs += 'src/test/kotlin'
} 

And applied the plugin, and added the dependencies:

apply plugin: 'kotlin-android'

dependencies {
    androidTestCompile deps.kotlin
    androidTestCompile deps.kotlinTest
    androidTestCompile deps.kotlinTestJunit
}

We have named dependencies in my projects’s build script:

ext.deps = [
    kotlin                : "org.jetbrains.kotlin:kotlin-stdlib:$ver.kotlin",
    kotlinTest            : "org.jetbrains.kotlin:kotlin-test:$ver.kotlin",
    kotlinTestJunit       : "org.jetbrains.kotlin:kotlin-test-junit:$ver.kotlin"
] 

I’m using Kotlin 1.0.5-2. Could someone help sort this out?