首页 > 解决方案 > Android测试用例等待10分钟后才能在debug模式下调试

问题描述

它以前工作过。但现在已经不行了。IDE 只显示“实例化测试...”。但是当我等了 10 分钟时,它突然就起作用了?该机器是 2015 年中的 Macbook Pro。问题仅出现在androidTesttest目录工作正常。

@LargeTest
@RunWith(AndroidJUnit4::class)
class SomeTestClass {

    @get:Rule
    var activityTestRule = ActivityTestRule(
            NavigationActivity::class.java, false, false)

    @Before
    fun before() {
        Timber.d("When debugging, this triggers only after about 10 minutes.")
    }

    @Test
    fun testContents() {
        Assert.assertEquals(0, 0)
    }    
}

日志不断输出:

D/EZIO_NLOG: watchdog_routine executed!
D/EZIO_NLOG: check1 
    check1 
    check2 
    check2 

尝试了以下事情:

  1. 文件,使缓存无效/重新启动
  2. 试过这个答案。但它似乎已经过时了。
  3. 编辑配置...,选择“All in Package”、“Class”和“Method”。它们都不起作用。
  4. 当我等了很长时间,比如 10 分钟,然后突然之间它就会触发并起作用。

在此处输入图像描述 在此处输入图像描述

标签: androidkotlintesting

解决方案


Android 测试很慢,并且在该调试器之上增加了更多负载。我遇到了同样的问题,我同意使用带有 Android 测试的调试器是一件痛苦的事情。

下面是我在这里找到的东西 Espresso detects when the main thread is idle, so it is able to run your test commands at the appropriate time, improving the reliability of your tests.

最重要的是,当添加调试器时,它会变得更慢。

您可以尝试在真实设备上运行测试,它应该更快(我假设)


推荐阅读