tim*_*dev 23 android unit-testing junit4 rx-java2
我打开示例代码BasicRxJavaSample(来自这篇文章Room + RxJava)主要的是:
@Rule
public InstantTaskExecutorRule instantTaskExecutorRule =
new InstantTaskExecutorRule();
Run Code Online (Sandbox Code Playgroud)
并且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'
Run Code Online (Sandbox Code Playgroud)
Pau*_*ira 46
通过androidTestImplementation替换testImplementation.因此对文件夹androidTest的测试可以访问该库.
dependencies {
androidTestImplementation "android.arch.core:core-testing:1.1.1"
}
Run Code Online (Sandbox Code Playgroud)
Kav*_*a_p 22
我知道已经晚了,但是我想为这个已接受的答案添加一件事,如果您想使用,
@Rule
public InstantTaskExecutorRule instantTaskExecutorRule =
new InstantTaskExecutorRule();
Run Code Online (Sandbox Code Playgroud)
在您的JUnit测试用例中,即在测试文件夹中,然后使用以下依赖项,即与testImplementation
dependencies {
testImplementation "android.arch.core:core-testing:1.0.0"
}
Run Code Online (Sandbox Code Playgroud)
如果要InstantTaskExecutorRule用于UI或集成测试用例,请使用androidTestImplementation。那是:
androidTestImplementation "android.arch.core:core-testing:1.0.0"
如果要同时添加两者,请使用androidTestImplementation和testImplementation,即:
androidTestImplementation "android.arch.core:core-testing:1.0.0"
testImplementation "android.arch.core:core-testing:1.0.0"
Abh*_*Das 20
对于androidX迁移,添加
androidTestImplementation "androidx.arch.core:core-testing:2.0.0"
Run Code Online (Sandbox Code Playgroud)
dependencies {
testImplementation "androidx.arch.core:core-testing:2.1.0"
}
Run Code Online (Sandbox Code Playgroud)
请将这两个依赖项放在您的 gradle 文件中,
dependencies {
// Test helpers for LiveData
testImplementation "android.arch.core:core-testing:1.0.0"
// Test helpers for Room
testImplementation "android.arch.persistence.room:testing:1.0.0"
}
Run Code Online (Sandbox Code Playgroud)
更多信息请访问此链接, Android 架构组件集成指南
| 归档时间: |
|
| 查看次数: |
8584 次 |
| 最近记录: |