android - Synchronize testing thread, UI thread, and CursorLoader thread -


my understanding android instrumented junit tests run on own thread unless annotated @uithread or calling instrumentation.runonmainsync() or activity.runonuithread(). i'm trying use cursorloader access app's database , populate listview. have test verifies listview populated correctly.

my problem need synchronize 3 threads: test thread should wait until cursorloader thread finishes , notifies ui thread populate listview. create cursorloader, register loadercallbacks support loadermanager , create instance in oncreateloader(). onloadfinished() changes cursor of listview's adapter.

now need ensure test waits until onloadfinish() has been called before attempting access child views of listview. current idea add waitfordata() method loadercallbacks implementation tests can call. however, i'm not sure how implement method. can use wait() , notifyall() in onloadfinished()? or need use more sophisticated semaphore?

you're on right track how go this. general approach indeed block main test thread until worker threads done. here's example using concurrentunit:

final waiter waiter = new waiter();  loadermanager.loadercallbacks callbacks = new loadermanager.loadercallbacks() {   public void onloadfinished(loader<d> loader, d data) {     waiter.assertequals(somevalue, "foo");     waiter.resume();   }    //... };   // register callbacks...  waiter.await(5000); // wait 5 seconds resume 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -