Instrumental Testing with FragmentScenario

后端 未结 3 2165
伪装坚强ぢ
伪装坚强ぢ 2021-02-14 21:27

I\'m trying to use the new FragmentScenario APIs of the androidx testing libraries for local testing and instrumentation testing(androidTest). The api works fine in local enviro

3条回答
  •  失恋的感觉
    2021-02-14 21:53

    You need to add "fragment-testing" dependency to the APK under testing instead of test APK.

    So please update your build.gradle to

    debugImplementation "androidx.fragment:fragment-testing:$fragment_version"
    

    from

    androidTestImplementation "androidx.fragment:fragment-testing:$fragment_version"
    

    (This is due to implementation details of FragmentScenario. "fragment-testing" declares Activity and is used by FragmentScenario. Activities declared in test APK runs in different process from APK under testing. In order to execute Fragment's code in the same process, you need to put "fragment-testing" library into your APK, not in test APK.)

    Here's also a tutorial page in developers site.

提交回复
热议问题