Cannot resolve ActivityTestRule after upgrading dependencies. Unable to import ActivityTestRule
Asked Answered
C

2

27

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

androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

I am using android support version 27.1.1

It is working fine with dependencies

androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
Captive answered 27/4, 2018 at 12:52 Comment(0)
F
50

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'
Fanchan answered 27/4, 2018 at 20:52 Comment(1)
Notice how the support.test:rules is not an Espresso dependency. It can now be used standalone. Also core suggests minimal dependency impact, I don't think it actually used any classes from rules. More control for us devs.Carnassial
V
1

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)
Vinegary answered 26/7, 2020 at 8:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.