错误:获取XmlPullParser对象的空值

时间:2019-01-09 05:12:49

标签: android unit-testing junit4

创建活动。通过Activity创建上下文并使用上下文加载的资源和XML文件。     XmlPullParser对象已创建,但它检索到的值为null。 为什么system.out.println返回-1,NULL,NULL,NULL? 代码块

@RunWith(RobolectricTestRunner.class)
@Config(manifest="src/main/AndroidManifest.xml", emulateSdk = 18)
public class BarGraph_Hor_WidgetTest {
private Activity objActivity;
    private ActivityController<Activity>  controller;
    private AttributeSet attrs;
    @Before
    public void setUp() throws Exception {        
       controller= Robolectric.buildActivity(Activity.class).create();
       controller.start();
       controller.visible();
       controller.resume();

        XmlPullParser parser = controller.get().getBaseContext().getResources().getXml(R.layout.widget_bargraph);
       attrs = Xml.asAttributeSet(parser);
       assertNotNull(attrs);

   System.out.println("ROBOLECTRIC " + parser.getAttributeCount());
       System.out.println("ROBOLECTRIC " + parser.getAttributeName(0));
       System.out.println("ROBOLECTRIC " + parser.getAttributeName(1));
       System.out.println("ROBOLECTRIC " + parser.getAttributeName(2));
}

0 个答案:

没有答案