使用Kotlin测试测试以Java语言编写的android应用

时间:2019-02-22 20:08:59

标签: java android android-studio kotlin uitest

我试图将UI测试添加到我的android应用中,决定使用kotlin而不是Java。 我在“ androidTest”文件夹中添加了一个新的kotlin文件 我关注了this tutrial 当我尝试运行测试时,我得到:

Empty test suite.

仅需强调-我正在用Kotlin编写测试程序,但该应用程序是用Java编写的,这样还可以吗?甚至无法正常工作?

我的代码:

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())
    }
}

谢谢。

1 个答案:

答案 0 :(得分:0)

一个漫长的夜晚后找到答案: 需要将此添加到mu Gradle文件

 sourceSets {
    test.java.srcDirs += 'src/test/kotlin/'
    androidTest.java.srcDirs += 'src/androidTest/kotlin/'
}
相关问题