我打开了示例代码BasicRxJavaSample(来自于这篇文章Room+RxJava)主要内容如下:
@Rule
public InstantTaskExecutorRule instantTaskExecutorRule =
new InstantTaskExecutorRule();
而BasicRxJavaSample是正常的。 但我无法在我的测试中应用它。 发生了什么:
无法解析符号InstantTaskExecutorRule
手动导入也不起作用:
但应该是这样的
我的app build.gradle (完整gradle请点击此处):
// tests
testImplementation 'junit:junit:4.12'
androidTestCompile "com.android.support:support-annotations:$supportVersion"
testImplementation "android.arch.core:core-testing:$archVersion"
// Test helpers for Room
testImplementation "android.arch.persistence.room:testing:1.0.0"
// https://github.com/mockito/mockito
testImplementation 'org.mockito:mockito-core:2.13.0'
androidTestImplementation 'org.mockito:mockito-android:2.13.0'
// AndroidJUnitRunner and JUnit Rules
androidTestImplementation 'com.android.support.test:rules:1.0.1'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
// https://developer.android.com/topic/libraries/testing-support-library/packages.html
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
androidTestCompile 'com.android.support.test.espresso:espresso-idling-resource:3.0.1'
androidTestImplementation
改成了testImplementation
,然后问题得到了解决并且可以运行了。 - Boyimport androidx.arch.core.executor.testing.InstantTaskExecutorRule
- Philipp Buhaievskiy