Cannot resolve ActivityTestRule after upgrading dependencies. Unable to import ActivityTestRule

前端 未结 2 1298
渐次进展
渐次进展 2021-02-07 00:16

I have written instrumentation tests which was working fine, but now getting error cannot resolve ActivityTestRule error after upgrading dependencies to

android         


        
相关标签:
2条回答
  • 2021-02-07 00:56

    In the most recent update of the Testing Support Library (2018-04-24), the "rules" dependency was apparently removed from the espresso-core. I'm not sure why this was done, but the release notes say this about the change:

    Fixed espresso-core POM file to not pull in "rules" dependency, instead have espresso-intents POM pull it. This should be a NoOp change for developers since espresso-intents cannot be used without espresso-core.

    You can fix this problem by adding the following dependency to app/build.gradle:

    androidTestImplementation 'com.android.support.test:rules:1.0.2'
    
    0 讨论(0)
  • 2021-02-07 01:13

    AndroidX Test includes another API,ActivityScenario that is currently in beta. This API works in a variety of testing environments and provides thread safety within the tests that use it. Consider using ActivityScenarioRule or ActivityScenario instead.

    import androidx.test.ext.junit.rules.ActivityScenarioRule
    
    ActivityScenarioRule(YourActivity::class.java)
    
    0 讨论(0)
提交回复
热议问题