android testing - Robolectric and View.getHeight() -
i'm trying test custom scrolling behavior changes location of view based on how far down user has scrolled. discovered though view scroll in robolectric 2.2, height of listview (and else) 0.
i read shadow objects , we're supposed call visible() when starting activity it'll drawn, , that's done. default layout listactivity listview match_parent height , width.
what's missing? why doesn't list have height?
@test public void testlistactivity() { final listactivity activity = robolectric.buildactivity(listactivity.class).create().start().resume().visible().get(); listview listview = activity.getlistview(); // set adapter items scroll. final arraylist<string> messages = new arraylist<>(); final int numberofchildren = 100; (int = 0; < numberofchildren; i++) { messages.add("test"); } final arrayadapter<string> listadapter = new arrayadapter<>(activity, android.r.layout.simple_dropdown_item_1line, messages); listview.setadapter(listadapter); assert.assertequals(listview.getcount(), numberofchildren); assert.asserttrue(listview.getheight() > 0); // fails. }
call populateitems() on shadow of listview after setting adapter:
... listview.setadapter(listadapter); shadowlistview shadowlistview = robolectric.shadowof(listview); shadowlistview.populateitems(); assert.asserttrue(listview.getheight() > 0); ...
Comments
Post a Comment