Android 测试用例只能在等待 10 分钟后在调试模式下进行调试

Jim*_*nts 5 testing android kotlin

它以前工作过。但现在它没有了。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)
    }    
}
Run Code Online (Sandbox Code Playgroud)

日志不断输出:

D/EZIO_NLOG: watchdog_routine executed!
D/EZIO_NLOG: check1 
    check1 
    check2 
    check2 
Run Code Online (Sandbox Code Playgroud)

尝试了以下事情:

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

在此处输入图片说明 在此处输入图片说明

小智 0

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.

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

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