带有Facebook SDK的Android Espresso AppNotIdleException

时间:2019-05-13 12:07:12

标签: android facebook android-espresso

当我在清单中添加Facebook SDK和applicationId时,Espresso测试不起作用 如果该类中有多种测试方法,则错误只会在第一次测试时发生

 <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/facebook_app_id" />

导致AppNotIdleException异常

E/TestRunner: androidx.test.espresso.AppNotIdleException: Looped for 2 iterations over 60 SECONDS. The following Idle Conditions failed .
        at dalvik.system.VMStack.getThreadStackTrace(Native Method)
        at java.lang.Thread.getStackTrace(Thread.java:1538)
        at androidx.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:94)
        at androidx.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:57)
        at androidx.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:316)
        at androidx.test.espresso.ViewInteraction.desugaredPerform(ViewInteraction.java:177)
        at androidx.test.espresso.ViewInteraction.perform(ViewInteraction.java:118)

如果我从清单中删除了com.facebook.sdk.ApplicationId,那么测试将正常运行

Android测试版本:

ext {
        kotlin_version = '1.3.31'
        koin_version = '2.0.0-rc-2'
        nav_version = '2.0.0'
        arch_version = '2.0.1'
        retrofit_version = '2.5.0'
        lifecycle_version = '2.0.0'
        glide_version = '4.9.0'
        espresso_version = '3.1.1'
    }
//  Facebook
    implementation 'com.facebook.android:facebook-login:4.42.0'

// Android test
    androidTestImplementation "androidx.arch.core:core-testing:$lifecycle_version"
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test:rules:1.1.1'
    androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_version"
    androidTestImplementation "androidx.test.espresso:espresso-intents:$espresso_version"
    androidTestImplementation 'androidx.test:core:1.1.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation "org.koin:koin-test:$koin_version"
    androidTestImplementation "org.mockito:mockito-android:2.25.0"
    androidTestImplementation 'com.squareup.okhttp3:mockwebserver:3.14.1'

    // Unit test
    testImplementation 'junit:junit:4.12'
    testImplementation "androidx.test:core:1.1.0"
    testImplementation "androidx.arch.core:core-testing:$lifecycle_version"
    testImplementation "org.koin:koin-test:$koin_version"
    testImplementation "org.mockito:mockito-core:2.27.0"
    testImplementation 'com.squareup.okhttp3:mockwebserver:3.14.1'

1 个答案:

答案 0 :(得分:0)

我遇到了相同的问题,并将其放入AndroidManifest.xml中进行了修复:

<application ...>
    <meta-data android:name="com.facebook.sdk.AutoInitEnabled" android:value="false"/>
</application>

其他信息:FB GDPR Compliance