如果getActivity()总是返回null,如何在android测试中获取活动?
public class PageDistrListTest extends ActivityUnitTestCase<PageDistrList> {
PageDistrList activity;
@Override
protected void setUp() throws Exception {
super.setUp();
activity = getActivity();
headerRecycler = (RecyclerView) activity.findViewById(R.id.page_tab_distr_recycler_header);
}
}
答案 0 :(得分:1)
您将获得此类活动实例
activity = launchActivity("package.PageDistrList", PageDistrList.class, null);
我不确定。请随时纠正我。