I have a database component that relies on AsyncTask
to retrieve data. Once used in the application it will always be called from the UI thread, but how do I do that in the JUnit tests without instantiating an Activity
(i just don't have an activity, nor should I have to create one just for testing purposes)?
runOnUiThread()
is an activity method so it's not an option. Is there a way to simulate the UI thread either by getting one from the Android test library or by implementing a MockUiThread?
Android.OS.Handler should be able to update the ui.
To use a handler you have to subclass it and overide handleMessage() to process messages
Update:
I am using monodroid, so I dont know if this is completely translatable, But,
You may be able to use
new Handler(context.getMainLooper()).post(runnable);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With