Jig*_*tel 5 android unit-testing android-espresso android-instrumentation androidx
我有一个包含 2 个模块的 android 项目。
我已经为两个项目设置了所需的测试依赖项,Gradle 配置相同。
当我从演示应用程序运行测试时,它运行没有任何问题。但是当从库模块运行相同的示例测试代码时,它无法找到测试。
这是我可以从 android studio 的“运行”选项卡中看到的日志。
演示模块测试 - 结果
$ adb shell CLASSPATH=$(pm path androidx.test.services) app_process / androidx.test.services.shellexecutor.ShellMain am instrument -r -w -e targetInstrumentation com.cardstream.paymentdemo.test/androidx.test.runner.AndroidJUnitRunner -e debug false -e class 'com.cardstream.paymentdemo.ExampleInstrumentedTest' androidx.test.orchestrator/androidx.test.orchestrator.AndroidTestOrchestrator
Client not ready yet..
Started running tests
Tests ran to completion.
Run Code Online (Sandbox Code Playgroud)
库模块测试 - 结果
$ adb shell CLASSPATH=$(pm path android.support.test.services) app_process / android.support.test.services.shellexecutor.ShellMain am instrument -r -w -e targetInstrumentation com.cardstream.payment.test/androidx.test.runner.AndroidJUnitRunner -e debug false -e class 'com.cardstream.payment.ExampleInstrumentedTest' android.support.test.orchestrator/android.support.test.orchestrator.AndroidTestOrchestrator
Client not ready yet..
Started running tests
Test running failed: No test results
Empty test suite.
Run Code Online (Sandbox Code Playgroud)
从上面的日志中,我可以看到两个模块使用的测试服务的差异。
演示模块 - androidx.test.services
库模块 - android.support.test.services
根据上述观察,我试图将这些转换为类似的行为,但不幸的是,我无法找到任何准确有效的答案或选项。
两个模块的 Instrumentation Runner 配置
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Run Code Online (Sandbox Code Playgroud)
两个模块的测试依赖项很少
testImplementation 'junit:junit:4.12'
testImplementation 'org.robolectric:robolectric:4.1'
androidTestImplementation 'androidx.test:core:1.1.0'
androidTestImplementation 'androidx.test:core-ktx:1.1.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test:rules:1.1.1'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestUtil 'androidx.test:orchestrator:1.1.1'
Run Code Online (Sandbox Code Playgroud)
我用库模块创建了一个新项目并运行测试,它适用于两个模块(带有支持库)。
我已经使用 AndroidX 迁移了新创建的项目,然后也适用于两个模块。
因此,我感到困惑,目前无法找出这种情况的解决方案。如果有人有任何线索/建议/答案,我期待着您的帮助?