Show a toast in android UI test
2017-07-31 本文已影响10人
JaedenKil
Normally if I try to show a toast in a non-ui android test , it ends up throwing an error :
can't create handler inside thread that has not called looper.prepare()
Xdroid-Toaster is sub-project of Xdroid Library. Simplify your life using Toaster :
- Context variable is not required.
- RunOnUiThread() is not required.
How :
Dependency
dependencies {
compile 'com.shamanland:xdroid-toaster:0.0.10'
}
Static import
import static xdroid.toaster.Toaster.toast;
import static xdroid.toaster.Toaster.toastLong;
Simple usage
// text from resource
toast(R.string.simplest_toast);
// hard-coded string
toast("Simplest hard-coded toast");
The details are Here.