首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >无法启动意图

无法启动意图
EN

Stack Overflow用户
提问于 2019-04-27 21:56:27
回答 1查看 499关注 0票数 0

下面是我的Espresso测试:

代码语言:javascript
复制
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import java.util.concurrent.TimeUnit

@RunWith(AndroidJUnit4::class)
class TradersActivityTest {
    private lateinit var mockServer: MockWebServer

    @Rule
    @JvmField
    var tradersIntentTestRule = IntentsTestRule(TradersActivity::class.java, false, false)

    @Before
    fun setup() {
        mockServer = MockWebServer()
        mockServer.start(8081)
    }

    @Test
fun hasTraders_noTradersTextView_isNotDisplayed() {
    mockServer.enqueue(MockResponse()
            .setResponseCode(200)
            .setBody(FileUtil.getStringFromFile(context, ONE_TRADER_NO_WALLETS_LIST)));
    tradersIntentTestRule.launchActivity(Intent())
    onView(withId(R.id.noTradersTextView))
            .check(matches(not(isDisplayed())))
}

    @Test
    fun toolBar_height() {
        onView(withId(R.id.toolBar))
                .check(matches(withHeightResId(R.dimen.tool_bar_height)))
    }

测试hasTraders_noTradersTextView_isNotDisplayed成功通过。

但测试toolBar_height失败,并显示以下消息:

代码语言:javascript
复制
java.lang.RuntimeException: No activities found. Did you forget to launch the activity by calling getActivity() or startActivitySync or similar?
at androidx.test.espresso.base.RootViewPicker.waitForAtLeastOneActivityToBeResumed(RootViewPicker.java:169)
at androidx.test.espresso.base.RootViewPicker.get(RootViewPicker.java:83)

因此,我更改了setup方法:

代码语言:javascript
复制
 @Before
    fun setup() {
        mockServer = MockWebServer()
        mockServer.start(8081)

        mockServer.enqueue(MockResponse()
                .setResponseCode(200)
                .setBody(FileUtil.getStringFromFile(context, ONE_TRADER_NO_WALLETS_LIST)));
        tradersIntentTestRule.launchActivity(Intent())

        Debug.d(TAG, "SUCCCESS_START_MOCKWEBSRVER")
    }

现在测试toolBar_height通过,但hasTraders_noTradersTextView_isNotDisplayed失败,并显示消息:

代码语言:javascript
复制
java.lang.RuntimeException: Could not launch intent Intent { flg=0x10000000 com.myproject.android.ui.activity.TradersActivity } within 45 seconds. Perhaps the main thread has not gone idle within a reasonable amount of time? There could be an animation or something constantly repainting the screen. Or the activity is doing network calls on creation? See the threaddump logs. For your reference the last time the event queue was idle before your activity launch request was 1556373134135 and now the last time the queue went idle was: 1556373143180. If these numbers are the same your activity might be hogging the event queue.
at androidx.test.runner.MonitoringInstrumentation.startActivitySync(MonitoringInstrumentation.java:459)

附注:我需要在测试hasTraders_noTradersTextView_isNotDisplayed中启动活动,因为它是一个特定的测试。但是我不想在测试toolBar_height中启动活动

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55881265

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档