Cannot resolve symbol 'ActivityTestRule' - SOLVED

Trying to copy the code from “For the more curious: Espresso and Integration Testing” Android Studio was unable to find any import for ActivityTestRule:

After some googling I found official Android documentation on this subject, which helpfully provides the necessary import statement. But even supplying this did not fix the issue. Android studio complains in the editor (and also the build continues to fail):

After further googling, I found the necessary gradle dependency on this Stack Overflow answer. And it works! Hoorah!

But beware: com.android.support.test:rules does not appear (for me) when searching for a library dependency in the UI:

If it did, I would have found the solution much sooner! So. Adding it manually to the app build.gradle was the solution:

02

(note, I’m using the recommended [android]TestImplementation rather than the book’s deprecated [android]TestCompile)