我的设备:三星S8
Espresso setup instructions的文档中说
为避免出现片状现象,我们强烈建议您关闭用于测试的虚拟或物理设备上的系统动画
我遵循了Android Testing Codelab上的Android UI测试教程。但是当我关闭系统动画时,测试失败。相反,当我打开系统动画时,测试通过了。
动画:上
Testing started at 7:44 PM ...
11/06 19:44:43: Launching addNoteToNotesList()
No apk changes detected since last installation, skipping installation of D:\Android\Exercise\android-testing-step-1-5\app\build\outputs\apk\prod\debug\app-prod-debug.apk
No apk changes detected since last installation, skipping installation of D:\Android\Exercise\android-testing-step-1-5\app\build\outputs\apk\androidTest\prod\debug\app-prod-debug-androidTest.apk
Running tests
$ adb shell am instrument -w -r -e debug false -e class 'com.example.android.testing.notes.notes.NotesScreenTest#addNoteToNotesList' com.example.android.testing.notes.test/android.support.test.runner.AndroidJUnitRunner
Client not ready yet..
Started running tests
Tests ran to completion.
动画:关闭
Testing started at 7:51 PM ...
11/06 19:51:04: Launching addNoteToNotesList()
No apk changes detected since last installation, skipping installation of D:\Android\Exercise\android-testing-step-1-5\app\build\outputs\apk\prod\debug\app-prod-debug.apk
No apk changes detected since last installation, skipping installation of D:\Android\Exercise\android-testing-step-1-5\app\build\outputs\apk\androidTest\prod\debug\app-prod-debug-androidTest.apk
Running tests
$ adb shell am instrument -w -r -e debug false -e class 'com.example.android.testing.notes.notes.NotesScreenTest#addNoteToNotesList' com.example.android.testing.notes.test/android.support.test.runner.AndroidJUnitRunner
Client not ready yet..
Started running tests
android.support.test.espresso.PerformException: Error performing 'scroll RecyclerView to: holder with view: has descendant: with text: is "UI testing for Android"' on view 'with id: com.example.android.testing.notes:id/notes_list'.
at android.support.test.espresso.PerformException$Builder.build(PerformException.java:82)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:79)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:51)
at android.support.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:312)
at android.support.test.espresso.ViewInteraction.desugaredPerform(ViewInteraction.java:173)
at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:114)
at com.example.android.testing.notes.notes.NotesScreenTest.addNoteToNotesList(NotesScreenTest.java:128)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:527)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at android.support.test.runner.AndroidJUnit4.run(AndroidJUnit4.java:101)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:384)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2106)
Caused by: java.lang.RuntimeException: Found 0 items matching holder with view: has descendant: with text: is "UI testing for Android", but position -1 was requested.
at android.support.test.espresso.contrib.RecyclerViewActions$ScrollToViewAction.perform(RecyclerViewActions.java:361)
at android.support.test.espresso.ViewInteraction$SingleExecutionViewAction.perform(ViewInteraction.java:356)
at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:248)
at android.support.test.espresso.ViewInteraction.access$100(ViewInteraction.java:63)
at android.support.test.espresso.ViewInteraction$1.call(ViewInteraction.java:153)
at android.support.test.espresso.ViewInteraction$1.call(ViewInteraction.java:150)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Tests ran to completion.
我不知道发生了什么。医生说要关闭它,但会使测试失败。这怎么会发生?