无法在Android测试中扩展活动

时间:2016-07-21 18:14:57

标签: java android testing android-espresso

我试图在我的测试类中访问一个全局变量。

    @Test
    public void checkInfo() 
{
    TM1Server mTm1Server = ((Quantum) this.getApplication()).getAdminServer().getTM1Server();
    String username = mTm1Server.getUsername();
    onView(withText("Info")).perform(click());
    onView(withText(username)).check(matches(isDisplayed()));
}

当原始编写此代码时,我收到错误"无法解决方法' getApplication()'。我最初的解决方案是添加"扩展活动"到我的班级,它允许测试编译,但出现了一个新的错误:

" java.lang.RuntimeException:无法在未调用Looper.prepare()"的线程内创建处理程序。

非常感谢你提前帮忙!

如果有人使用EpicPandaForce,将来会有这个问题

TM1Server mTm1Server = ((Quantum) mActivityRule.getActivity().getApplication()).getAdminServer().getTM1Server();

并且不会延长活动。

0 个答案:

没有答案
相关问题