Search code examples
javaandroidandroid-studiokotlinuitest

Test android app writen in java with kotlin test


I'm trying to add UI-tests to my android app, decided to work with kotlin and not with Java. I have added a new kotlin file to my "androidTest" folder I followed this tutrial When I'm trying to run the test i'm getting:

Empty test suite.

just to emphasize - I'm writing to test in kotlin but the app is written in Java, is that even ok? or it can't even work?

My code:

package maakesher.com.black.packagename
import android.support.test.espresso.Espresso.onView
import android.support.test.espresso.action.ViewActions.click
import android.support.test.espresso.matcher.ViewMatchers.withId
import android.support.test.rule.ActivityTestRule
import androidx.test.filters.LargeTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test

@LargeTest
class ChangeTextBehaviorTest {

    private lateinit var stringToBetyped: String

    @get:Rule
    var activityRule: ActivityTestRule<MainMenuActivity> = ActivityTestRule(MainMenuActivity::class.java)

    @Before
    fun initValidString() {
        // Specify a valid string.
        stringToBetyped = "Espresso"
    }

    @Test
    fun testSomeStuff() {
        // Type text and then press the button.
        onView(withId(R.id.start_button))
                .perform(click())
    }
}

Thanks.


Solution

  • After a long night found the answer: Needed to add this to mu Gradle file

     sourceSets {
        test.java.srcDirs += 'src/test/kotlin/'
        androidTest.java.srcDirs += 'src/androidTest/kotlin/'
    }