仪器测试 apk 要么没有测试,要么在添加房间测试后运行

The instrumentation test apk either has no tests or the runner after adding room testing

我遵循了 Florina Muntenescu 的 article about room migration tests,在我的 gradle 文件中添加了房间测试后,我在 运行 我的 UI 测试时开始出现此错误:

java.lang.ClassNotFoundException: Didn't find class 
"br.com.jonathanzanella.TestRunner" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", 
zip file "/data/app/br.com.jonathanzanella.myexpenses.debug.test-1/base.apk", 
zip file "/data/app/br.com.jonathanzanella.myexpenses.debug-1/base.apk"],
nativeLibraryDirectories=[/data/app/br.com.jonathanzanella.myexpenses.debug.test-1/lib/x86, /data/app/br.com.jonathanzanella.myexpenses.debug-1/lib/x86, /vendor/lib, /system/lib]]

我正在使用来自架构组件的空间和生命周期可观察值:

implementation "android.arch.lifecycle:extensions:$roomVersion"
implementation "android.arch.persistence.room:runtime:$roomVersion"
implementation "android.arch.persistence.room:rxjava2:$roomVersion"
androidTestImplementation "android.arch.persistence.room:testing:$roomVersion"
kapt "android.arch.persistence.room:compiler:$roomVersion"

房间版本为 1.0.0

我有一个自定义测试运行器:

testInstrumentationRunner 'br.com.jonathanzanella.TestRunner'

TestRunner class 在 androidTest 文件夹中定义。

在 facebook 截图测试中查看 this issue 让我认为问题在于房间测试也定义了一个 customRunner 并且我需要按照问题解决方案中所示覆盖它,但是代码

project.app.customTestRunner = true

不为我编译

在堆栈溢出时挖掘这里,我发现这个 question 让我认为错误可能是其他原因。

由于 room 有一个我需要添加到 kapt 的编译器,我尝试将其添加为 kapt 在 androidTest 中的依赖项,并且它解决了问题。

解决问题的代码是这样的:

kaptAndroidTest "android.arch.persistence.room:compiler:$roomVersion"