Tag: 浓咖啡

在espresso测试中“无法启动活动”

这是我的完整代码 ,当我测试下面的代码与“Android测试”,它会引发错误“无法启动活动” //TestPlayer.kt public class PlayerTest : ActivityInstrumentationTestCase2<Player>(Player::class.java) { override fun setUp() { super.setUp() getActivity() } fun testPlayer() { onView(withId(R.id.player)).perform(doubleClick()) } } 我没有在Android显示器中找到任何输出,如何调试?

在浓缩咖啡测试超时,测试不运行

有一个辅助类DialogIdlingResource,我试着运行我的测试。 测试发生,除了这一个。 按下按钮后,一切都停止。 AcceptanceHelper.clickOnButtonInLayout(R.id.mainSignButton, R.string.common_signin_button_text, R.id.inputLayout) 带有两个辅助方法的代码片段: @Test fun signInUserWithInvalidEmail() { goToSignIn() AcceptanceHelper.updateValidationTextView(R.string.ui_data_attribute_email, "kokojambo@mail.ru") AcceptanceHelper.updateValidationTextView(R.string.ui_data_attribute_password, VALID_PASSWORD) AcceptanceHelper.clickOnButtonInLayout(R.id.mainSignButton, R.string.common_signin_button_text, R.id.inputLayout) val idlingResource = DialogIdlingResource() registerDialogIdlingResource() unregisterDialogIdlingResource() } private fun registerDialogIdlingResource() { val instrumentation = InstrumentationRegistry.getInstrumentation() idlingResource = DialogIdlingResource() Espresso.registerIdlingResources(idlingResource) } private fun unregisterDialogIdlingResource() { Espresso.unregisterIdlingResources(idlingResource) } 可能由于regester和unregister(idlingResource)两种方法导致的错误, 但实际上它应该可以工作,但也可能是某个可能犯了错误的地方,即辅助类代码: class DialogIdlingResource(private val waitTimeSeconds: Int = 5) : […]

多次运行浓缩咖啡测试

有时我遇到了我的应用程序中的罕见错误。 但是我不能重现它,因为它非常罕见。 所以,我决定写简单的咖啡测试: @RunWith(AndroidJUnit4::class) @LargeTest class MainActivityTest { val password = "1234" @Rule @JvmField var mActivityRule: ActivityTestRule<MainActivity> = ActivityTestRule(MainActivity::class.java) @Test fun checkNotesListNotEmpty() { onView(withId(R.id.password_edit_text)).perform(typeText(password)) onView(withId(R.id.notes_recycler_view)).check { view, noMatchingViewException -> if (noMatchingViewException != null) throw noMatchingViewException assertThat((view as RecyclerView).adapter.itemCount, Matchers.`is`(1)) } } } 如何循环测试并在匹配失败时停止测试?

Android Espresso – 如何在所有测试中只运行一次安装程序

我正在使用Espresso / Kotlin来运行我们的Android应用程序的测试,我想在给定的测试类中的所有测试运行一次。 我创建了一个伴侣对象来启动应用程序一次(它这样做),然而它随后关闭,并且在每次测试运行时都不会保持打开状态。 我怎样才能启动应用程序,运行测试类中的所有测试,然后关闭应用程序? 我也尝试了以下,但它仍然启动一次然后关闭,然后尝试运行测试:

为什么Kotlin允许在不同的文件夹(例如main和androidTest)中有两个具有相同名称和包的类?

我发现在Kotlin中,可能有两个同名的类,在同一个包中,但是其中一个在androidTest文件夹中,运行Espresso测试时,它将成为这个类中的一个。 这在Java下是不可能的,我想知道这是否是一个预期的行为,或者是由于其他原因。 在图像中,Kotlin中的AppCollaborator存在于androidTest和main中,AS不会抱怨,但是它关于JavaCollaborator。 事实是,这种行为是非常有用的,为了在测试(API等)期间加倍一些类,但我不知道我是否可以依靠它。

在咖啡测试中,注解被kotlin忽略了吗?

我有用kotlin编写的测试类,并使用espresso来执行测试。 当我运行它时,用@Before注释的函数被完全忽略。 即使在调试测试并在其中放置断点时,也不能通过这一点。 你有什么想法,为什么发生这种情况? 我一直在谷歌搜索,但大多数例子不使用@Before或根本不提及任何问题。 我还添加了logOut()函数以获取更多信息。 PD:在Java中编写相同的代码完美地工作。 @RunWith(AndroidJUnit4::class) class LoginTest { @get: Rule val activityTestRule = ActivityTestRule(SplashActivity_::class.java) private lateinit var user: User @Before fun setUp() { logOut() } @Test fun newUserWasLoggedIn() { givenAnUser(UserFactory.randomUser) itCanBeLoggedAsNewUser() } @Test fun oldUserWasLoggedIn() { givenAnUser(UserFactory.oldUser) itCanBeLoggedAsOldUser() } private fun itCanBeLoggedAsOldUser() { oldUserLogin(user) } private fun itCanBeLoggedAsNewUser() { newUserLogin(user) } private […]