android - Assert that ActionBar item becomes visible after CAB is dismissed -
android - Assert that ActionBar item becomes visible after CAB is dismissed -
i have next 2 tests shown:
public void testonclickcheckboxstartactionmode() { int index = 4; this.solo.clickoncheckbox(index); assert.asserttrue(this.solo.waitforview(r.id.delete_menu)); } public void testonclickcheckboxstopactionmode() { this.testonclickcheckboxstartactionmode(); int index = 4; this.solo.clickoncheckbox(index); view addmenu = this.activity.findviewbyid(r.id.add_menu); assert.assertnotnull(addmenu); assert.asserttrue(addmenu.isshown()); }
the first checks actionmode correctly started when item in listview checked. sec checks actionmode stops after unchecking listview item. problem testonclickcheckboxstopactionmode()
fails on line assert.asserttrue(addmenu.isshown());
. can manually verify right behavior in app, test seems broken. believe problem assertion occurs before ui thread has chance remove cab , restore regular actionbar.
i have tried instrumentation.runonmainsync()
in order synchronize test ui thread:
this.inst.runonmainsync(new runnable() { @override public void run() { view addmenu = activity.findviewbyid(r.id.add_menu); assert.assertnotnull(addmenu); assert.asserttrue(addmenu.isshown()); } });
it still fails @ same assertion. worse, entire test suite stops, rather signaling failed test , continuing next one, because assertionfailederror
thrown on separate thread.
how synchronize main thread in order verify actionbar
menu items indeed visible @ end of tests?
i able prepare problem inserting phone call solo.waitforview()
:
public void testonclickcheckboxstopactionmode() { this.testonclickcheckboxstartactionmode(); int index = 4; this.solo.clickoncheckbox(index); // added call: assert.asserttrue(this.solo.waitforview(r.id.add_menu)); view addmenu = butterknife.findbyid(this.activity, r.id.add_menu); assert.assertnotnull(addmenu); assert.asserttrue(addmenu.isshown()); }
strangely, had tried modifying test waitforview()
while fixing bug. however, lone didn't cause test fail in presence of bug. on other hand, addmenu.isshown()
didn't pass after bug fixed. apparently combination of both required test correct.
android testing race-condition instrumentation
Comments
Post a Comment