これはバグだと思うが、間違っていると思われる。ビューに浮動アクションボタンが含まれている場合にのみスナックバーが表示されるときにAndroidエスプレッソテストがフリーズする
私のレイアウトは非常にシンプルであり、唯一のフローティングアクションボタンが含まれています
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/contentCoordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/layoutWithoutContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/stopButton"
android:src="@drawable/ic_stop_white_24px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
app:layout_anchor="@id/layoutWithoutContent"
app:backgroundTint="@color/colorPrimary"
app:layout_anchorGravity="bottom|right|end"/>
私の活動が唯一のonCreateメソッドを含む継承:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CoordinatorLayout coordinatorLayout = findViewById(R.id.contentCoordinatorLayout);
Snackbar.make(coordinatorLayout, R.string.snackbar_message, Snackbar.LENGTH_LONG).show();
}
私はどのエスプレッソテストを書きましたSnackbarが1/2秒以内に表示されることを確認するだけです
@Rule
public ActivityTestRule<MainActivity> mainActivity = new ActivityTestRule<>(MainActivity.class, true, true);
@Test
public void testSnackbarIsShown() throws Exception { onView(withText(R.string.snackbar_message)).check(matches(isDisplayed()));
}
このテストをデバッグすると、の後にonView(withText(R.string.snackbar_message)).check(matches(isDisplayed()));
が実行され、のスナップバーが表示されなくなります。
際にこれまでのところ、私はこの問題を解決する3つの方法を発見した、問題が解決されています。私はトップにFloatingActionButtonのanchorGravity変更
:
app:layout_anchorGravity="top|right|end"
を私はFloatingActionButtonを削除し、完全
Snackbarの最初の引数を
findViewById(android.R.id.content)
に変更します。しかし、これはSnackbarが現れるときにFloatingActionButtonを押し上げることはありません。
私が言ったように、私はこれはバグだと思っていますが、ここで何か間違っているのかどうか教えてください。
'sleep()'メソッドを使うのは間違いです。テストトレッドをループする 'ViewAction'を使うべきです。エスプレッソはアニメーションでうまく動作しないということもあります。デバイス開発者のオプションでアニメーションをオンにし、テストを開始しようとします。 –
@KarolKulbakaアニメーションがオフになっていて、睡眠がなくても、テストはハングアップします。 – Sammekl
'ActivityMonitor'で試しましたか? (https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor.html)同様に、アクティビティが表示されるのを待って、スナックバーを確認した後でなければなりません。 –