我有一些针对Android的仪器测试。当我在Android Studio(模拟和设备上)中运行它们时它们很好,但是当我在AWS设备场上运行它们时,其中一些失败并出现错误:
java.lang.RuntimeException:无法启动活动android.support.test.runner.MonitoringInstrumentation.startActivitySync(MonitoringInstrumentation.java:371)
他们似乎是测试片段的人,但这可能会产生误导。我是Android新手,但我认为他们都运行相同的apk?
测试:
package uk.co.stuff
import android.support.test.espresso.Espresso.onView
import android.support.test.espresso.assertion.ViewAssertions.matches
import android.support.test.espresso.matcher.ViewMatchers.isDisplayed
import android.support.test.espresso.matcher.ViewMatchers.withText
import android.support.test.filters.LargeTest
import android.support.test.runner.AndroidJUnit4
import android.support.v4.app.FragmentActivity
import com.android21buttons.fragmenttestrule.FragmentTestRule
import org.hamcrest.CoreMatchers.not
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import uk.co.stuff.MyFragment
import uk.co.stuff.models.Driver
import uk.co.stuff.utils.Constants
import uk.co.stuff.utils.DatabaseUtil
@RunWith(AndroidJUnit4::class)
@LargeTest
class ProfileFragmentShould {
@Rule
@JvmField
val fragmentTestRule =
FragmentTestRule(FragmentActivity::class.java, MyFragment::class.java, true, true)
@Test
fun not_show_payment_details() {
DatabaseUtil.setUser(Driver().apply { type = Constants.INDEPENDENT_DRIVER })
fragmentTestRule.launchFragment(MyFragment())
val paymentDetails =
fragmentTestRule.activity.getString(R.string.payment_details)
onView(withText(paymentDetails)).check(matches(not(isDisplayed())))
}
}
答案 0 :(得分:0)
我使用的是错误的apk。我需要使用构建和汇编AndroidTest时生成的debug和androidTest版本