0
ユーザーがViewPagerでスワイプしたりTabViewをタップしたりすると、タブビューのタイトルがフラグメントのタイトルと「同期」することを確認するテストを追加します。ViewPagerのフラグメントとタブビューの同期を確認するためのAndroid Espressoテスト
私はもっと簡単なことをやっていますが、テストではonView(...)という行で無限ループが発生します。私はdinamicallyタブを追加している
...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/pager_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
app:tabGravity="fill"
app:tabMode="scrollable" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" />
</LinearLayout>
...
:
@RunWith(AndroidJUnit4.class)
public class MyActivityTest {
@Rule
public ActivityTestRule mActivityRule = new ActivityTestRule<>(
MyActivity.class);
@Test
@android.support.test.annotation.UiThreadTest
public void switchTab() {
((MyActivity)mActivityRule.getActivity()).addMyTab("Test 1", true);
onView(withText("Test 1"))
.perform(click())
.check(matches(withText("Test 1")));
}
そして、これは私のXMLである:ここでは
コードです私が使用しているように、アダプタ:
mTabLayout.setupWithViewPager(mPager);
...
myAdapter.add(...);