I'm trying to test DrawerLayout by using Robolectric 3.0 The problem is isDrawerVisible method always return false, probably the layout is not inflated yet, though I'm not sure. My first test is to check whether a certain click will open drawer or not.
Fragment fragment = FragmentTestUtils.startVisibleFragment(someFragment);
View rootView = fragment.getView();
DrawerLayout drawerLayout = (DrawerLayout) rootView.findViewById(R.id.drawer_layout);
drawerLayout.openDrawer(GravityCompat.START);
assertThat(drawerLayout.isDrawerVisible(GravityCompat.START)).isTrue();
Since the drawer has slide animation, I don't know whether this affect this issue or not. Although regarding to some answers, isDrawerVisible should be working even the animation is not completed.
Then I wanted to check whether a certain view exists or not in the drawerlayout but any attempt by using
drawerLayout.findViewById(R.id.foo)
returns null since it's not on the screen yet. Solving the first issue will help to solve the latter one I assume.
PS: I even used some delay before assertion.
Aucun commentaire:
Enregistrer un commentaire