【发布时间】:2019-02-22 20:08:58
【问题描述】:
我正在尝试将 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())
}
}
谢谢。
【问题讨论】:
-
这不是直接的答案,这就是我要发表评论的原因。我不知道如何解决这个问题,我查了一堆答案,没有一个能解决它。 IntelliJ 和 Android Studio 似乎都受到了影响。进入命令行并手动运行它们至少修复了单元测试(
./gradlew test或gradlew test),但我不确定 UI 测试是否包含在测试任务中。 AS 和 IntelliJ 做了很多奇怪的事情,在使用命令行时会立即修复 xd -
另外,根据我的观察,手动编译测试 (
gradlew test) 也修复了“空测试套件”问题。但是到那时已经为时已晚,代码已经编译和测试了
标签: java android android-studio kotlin uitest