3

Espresso で NineOldAndroids lib に基づいてアニメーションを繰り返すアクティビティ (HomeActivity) をテストしようとしています。こちらで説明されているようにシステム アニメーションをオフにしましたが、効果がなく、エラーが発生します (以下を参照)。アニメーションを手動で削除することだけが役に立ちます。質問は、アニメーションを手動でオフにする必要があるか (BuildConfig を使用すると手間がかからないように見える)、それとも何か間違っているのでしょうか? 前もって感謝します!

 java.lang.RuntimeException: Could not launch intent Intent {
 act=android.intent.action.MAIN flg=0x14000000
 cmp=com.package.en/com.package.ui.HomeActivity } within 45 seconds.
 Perhaps the main thread has not gone idle within a reasonable amount
 of time? There could be an animation or something constantly
 repainting the screen. Or the activity is doing network calls on
 creation? See the threaddump logs. For your reference the last time
 the event queue was idle before your activity launch request was
 1392052899081 and and now the last time the queue went idle was:
 1392052899081. If these numbers are the same your activity might be hogging the event 
 queue.
4

2 に答える 2

3

問題の修正:

    @Before
    public void setUp() throws Exception {
        super.setUp();
        injectInstrumentation(InstrumentationRegistry.getInstrumentation());
        Intent intent = getIntent();
        if (intent == null) {
            intent = new Intent();
        }
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        setActivityIntent(intent);
    }

    @SuppressLint("NewApi")
    @Override
    public T getActivity() {
        final T activity = super.getActivity();
        activity.overridePendingTransition(0, 0);
        return activity;
    }

于 2016-04-15T10:42:08.453 に答える
1

私は 9olddroids についてはあまり知りませんが、Espresso では、テストの信頼性を高めるためにアニメーションを無効にする必要があります。

したがって、アニメーションを無効にするコードを追加することで、アプリの「テスト容易性」を高めることができます。たとえば、次のようなアニメーションを無効にするメソッドをアクティビティに含めることができます。

 public void disableAnimations() {
     this.mAnimationsEnabled = false;
 }

また、すべてのアニメーションの前に、アニメーションが有効になっているかどうかを確認します。テストが開始されたら、アニメーションを無効にします。

 public void setUp () {
    super.setUp();
     YourActivity activity = getActivity();
     activity.disableAnimations();
 }

 public void testXYZ() {
     // your test code
 }

9OldDroids が Espresso に干渉しなくなるので、これが機能することを願っています

于 2014-02-15T17:17:33.447 に答える