我什么时候
@Before
public void setUp() throws Exception {
Activity activity = Robolectric.buildActivity(ActivityMain.class).create().get();
}
运行测试之后它给了我错误org.fest.reflect.exception.ReflectionError: Unable to find method '$$robo$getData'
我正在使用eclipse
和ant build来测试robolectric
的{{1}}测试。
但是这段代码在我的测试中运行良好
android
所以它确认该程序能够获得@Test
public void testBasicResourceValue() throws Exception {
String helloFromActivity = new ActivityMain().getResources().getString(R.string.str_my_file);
assertThat(helloFromActivity, equalTo("newfile"));
}
答案 0 :(得分:0)
活动活动= Robolectric.buildActivity(ActivityMain.class).create()得到()。这个 线是不能与ANT构建我不知道为什么?我听说 robolectric停止支持ANT.So我找到了另一种解决方法 对于此问题,通过使用获取活动的阴影对象 下面给出的代码
@Before
public void setUp() throws Exception {
MyActivity activity = new MyActivity();
//Remember setContentView() has to call before you are trying to get any resource ID from the activity like Button,TextView etc other wise you will get the not shadow object for those views.
activity.setContentView(R.layout.warning);
Assert.assertNotNull(activity);
}