For some reason, Toast.makeText().show() and dialog.show() calls do nothing when called from test methods in an ActivityInstrumentationTestCase2 class.
Does anyone know why or how to fix this?
Example:
public class MyTest extends ActivityInstrumentationTestCase2<MyActivity> {
public MyTest(String name)
{
super("com.mypackage.activities", MyActivity.class);
setName(name);
}
public exampleTest()
{
//This works to show that the test class is running correctly
TouchUtils.drag(this, 200.0F, 200.0F, 300.0F, 300.0F, 5);
//The following line does nothing
Toast.makeText(getActivity(), "toast message", Toast.LENGTH_LONG).show();
//Sleep to make sure we can see the message
SystemClock.sleep(5000);
}
}
You need perform your code on Application’s UI thread:
Hope this helps.