2016-08-18 30 views
1

禁用動畫我已經做了這些步驟咖啡單元測試:如何在代碼

爲了避免片狀,我們強烈建議您關閉系統的動畫用於測試的虛擬或物理設備(一個或多個)上。

在設備上,在設置 - >開發人員選項禁用以下3個設置:
窗口動畫縮放
過渡動畫縮放
動畫長比例

但地方在我的代碼我用這個

animation = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 
animation.setInterpolator(new LinearInterpolator()); 
animation.setRepeatCount(Animation.INFINITE); 
animation.setDuration(5000); 
imageScanLogo.startAnimation(animation); 

在我的Espresso Test課程中,我用

對該視圖執行單擊
onView(withId(R.id.imageScanLogo)).perform(click()); 

之後,它卡在那一點,不再提前。當我將代碼中的動畫評論出來時,它可以正常工作。 這是堆棧跟蹤,它說他無法點擊視圖,但事實上他點擊了它,並沒有在測試中進一步發展。

android.support.test.espresso.PerformException: Error performing 'single click - At Coordinates: 539, 946 and precision: 16, 16' on view 'with id: com.android.x.y/imageScanLogo'. 
at android.support.test.espresso.PerformException$Builder.build(PerformException.java:83) 
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:80) 
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:56) 
at android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:184) 
at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:115) 
at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:87) 
at com.android.x.y.BaseTests.scanTagsAndUpload(BaseTests.java:88) 
at com.android.x.y.CleanScanTest.scan(CleanScanTest.java:61) 
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 org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) 
at android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55) 
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:270) 
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 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:59) 
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262) 
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1879) 
Caused by: android.support.test.espresso.AppNotIdleException: Looped for 4864 iterations over 30 SECONDS. The following Idle Conditions failed . 
at android.support.test.espresso.IdlingPolicy.handleTimeout(IdlingPolicy.java:61) 
at android.support.test.espresso.base.UiControllerImpl.loopUntil(UiControllerImpl.java:480) 
at android.support.test.espresso.base.UiControllerImpl.loopUntil(UiControllerImpl.java:411) 
at android.support.test.espresso.base.UiControllerImpl.injectMotionEvent(UiControllerImpl.java:229) 
at android.support.test.espresso.action.MotionEvents.sendUp(MotionEvents.java:138) 
at android.support.test.espresso.action.MotionEvents.sendUp(MotionEvents.java:118) 
at android.support.test.espresso.action.Tap.sendSingleTap(Tap.java:135) 
at android.support.test.espresso.action.Tap.access$100(Tap.java:35) 
at android.support.test.espresso.action.Tap$1.sendTap(Tap.java:40) 
at android.support.test.espresso.action.GeneralClickAction.perform(GeneralClickAction.java:98) 
at android.support.test.espresso.ViewInteraction$1.run(ViewInteraction.java:144) 
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423) 
at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

我超時策略設置這樣

@Before 
    public void resetTimeout() { 
     IdlingPolicies.setMasterPolicyTimeout(30, TimeUnit.SECONDS); 
     IdlingPolicies.setIdlingResourceTimeout(20, TimeUnit.SECONDS); 
    } 

我不希望每一個動畫註釋掉的代碼,也沒有開始建立一些標誌是否啓用/禁用動畫進行測試。

回答

1

當應用程序處於空閒狀態(所有AsyncTask已完成)時,Espresso只對視圖執行驗證。默認情況下,它會等待60秒然後拋出AppNotIdleException,您將此更改爲30秒,在此期間您的應用尚未閒置,因此將其更改爲更高的值可能會有所幫助。

+0

不改變任何東西。它在我註釋掉動畫的時候起作用。 –

+0

是的,我認爲動畫可能需要長達30秒才能完成,因此您的應用沒有被怠速。請更改30s到更高Ex:60s,90s再次檢查 – Binngokute

+1

它是無限的.. –

1

嘗試使用Animator API,因爲它的the preferred animation method since Honeycomb (3.0)

ObjectAnimator anim = ObjectAnimator.ofInt(imageScanLogo, "rotation", 0, 360); 
anim.setRepeatCount(ValueAnimator.INFINITE); 
animation.setInterpolator(new LinearInterpolator()); 
animation.setDuration(5000); 
anim.start(); 

也許咖啡不檢查舊的動畫API或開發者設置禁用動畫並不適用於舊的動畫。