未调用Android InstrumentationTestCase runTestOnUiThread

时间:2015-10-22 09:54:32

标签: android android-testing

我正在尝试在InstrumentationTestCase中的UI线程上运行非常简单的代码,但它从未调用过。例如,此测试通过。我怎样才能正确运行?

public class Test1 extends InstrumentationTestCase {

    @Test
    public void testUI() throws Throwable {
        final CountDownLatch signal = new CountDownLatch(1);

        runTestOnUiThread(new Runnable() {
            @Override
            public void run() {
               fail();
            }

        });

        try {
            signal.await(30, TimeUnit.SECONDS); // wait for callback
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}

0 个答案:

没有答案