Cannot import android.arch.persistence.room.testing.MigrationTestHelper

Since the code use AndroidJUnit4 then Just use androidTestCompile instead

 androidTestCompile "android.arch.persistence.room:testing:$arch_version"

Official doc use dependency for local unit test. However, the official sample use Android runner...

https://developer.android.com/topic/libraries/architecture/adding-components.html


You are using Android runner (AndroidJUnit4.class), and your test is actualy placed at src/androidTest. It means you are using Instrumented Tests which dependencies should be declared:

// Instrumented Unit Test or UI Test
androidTestComplile ....  

Meanwhile, if you are writing Local Unit Test, testing codes is placed at src/test, you can declare the dependencies:

// Local Unit Test
testCompile ....

In Google documentation, they just give an example for local unit tests. No mistake here.


The main issue is google provide documentation for JUnit local tests cases and not instrumental (which means tests on a real device or emulator).

As a result i saw many example with

testImplementation "androidx.room:room-testing:$room_version"

This makes not sense cause you can only test your room db with instrumental test cases. You will get an error otherwise. So you have to use androidTestImplementation and not testImplementation in your gradle file.

def room_version = "2.2.5"
def test_version = "1.2.0"
androidTestImplementation "androidx.test:runner:$test_version"
androidTestImplementation "androidx.test:rules:$test_version"
androidTestImplementation "androidx.room:room-testing:$room_version"