我在单击代码时遇到问题,我的代码仍然错误
Espresso.onView(withId(R.id.recyclerLastMatchlist))
.perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(1, ViewActions.click()))
这是依赖项
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test:rules:1.1.0'
androidTestImplementation("com.android.support.test.espresso:espresso-contrib:2.2.2") {
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'design'
exclude group: 'com.android.support', module: 'recyclerview-v7'
}
答案 0 :(得分:0)
根据您对gradle的依赖,您的应用似乎使用的是com.android.support
,而不是androidx
。在这种情况下,您之所以得到NoViewMatchException
,是因为您的测试试图在androidx.recyclerview.widget.RecyclerView
而非android.support.v7.widget.RecyclerView
上执行操作,这显然是不同的。
因此,请尝试替换依赖项:
//androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
//androidTestImplementation 'androidx.test:runner:1.1.0'
//androidTestImplementation 'androidx.test:rules:1.1.0'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'