Mic*_*ovo 9 android android-espresso
我有以下Espresso测试.如果我自己运行它总是通过,但是当我一起运行类中的所有测试时总是失败.
有点奇怪的是,它曾经作为套件的一部分工作.我不知道为什么它现在停止工作了.它一定是我做过的,但我不知道是什么.
@Test
public void itemHasImage_ShowsImage() {
closeSoftKeyboard();
if (mItem.getImageUrl() != null) {
onView(withId(R.id.edit_item_image)).perform(scrollTo())
.check(matches(isDisplayed()));
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
Error performing 'scroll to'...
...
Caused by: java.lang.RuntimeException: Action will not be performed
because the target view does not match one or more of the following
constraints:(view has effective visibility=VISIBLE and is descendant
of a: (is assignable from class: class android.widget.ScrollView...
Run Code Online (Sandbox Code Playgroud)
视图是可见的,是滚动视图的后代,正如它在自己运行时传递所证明的那样.
当它进入这个测试(在套件中)它只是不滚动.但是当我单独运行它时它滚动得很好.
在另一个堆栈溢出问题中,我问最近Espresso没有在参数化测试中第二次迭代启动Activity相同,我发现上一次测试中的onDestroy在当前测试中的onResume之后被调用,导致它将值设置为null并失败考试.在这种情况下,问题是测试本身通过但不在套件中.我现在有类似的问题,但没有明显的方法来解决它.(编辑:无法再应用其他问题的解决方法).
任何人的想法?它能以某种方式阅读错误的活动吗?也许它正在看着之前测试中的那个.这听起来很荒谬,但在最后一个问题之后我觉得有可能.
编辑:好的,事实证明,当作为套件的一部分运行此测试时,图像实际上是不可见的,导致测试失败.我发现这是使用调试器并手动滚动视图.但为什么?
我认为这是一个错误,并在此处记录了一个问题:
它可以使用Orchestrator android测试实用程序库解决,它将独立执行每个测试用例,因此没有中断测试套件的机会
启用build.gradle
android {
defaultConfig {
...
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
testOptions {
execution 'ANDROID_TEST_ORCHESTRATOR'
}
}
dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestUtil 'com.android.support.test:orchestrator:1.0.1'
}
Run Code Online (Sandbox Code Playgroud)
有关更多信息:https : //developer.android.com/training/testing/junit-runner.html#using-android-test-orchestrator
| 归档时间: |
|
| 查看次数: |
3077 次 |
| 最近记录: |