1
何らかの理由で、Toast.makeText()。show()およびdialog.show()呼び出しは、ActivityInstrumentationTestCase2クラスのテストメソッドから呼び出されたときに何もしません。トーストとダイアログがなぜActivityInstrumentationTestCase2から機能しないのですか?
これを修正する理由や方法は誰にも分かりますか?
例:あなたがアプリケーションのUIスレッド上でコードを実行する必要がある
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);
}
}
Thread.sleepの使用は実行されたものではありません。あなたのテストでは 'Instrumentation.runOnMainSync'を使うべきです - アプリケーションのメインスレッドで呼び出しを実行し、完了するまでブロックします。 – Daniel