需要测试属性是否已设置,如何使用Roboletric进行此操作?
private MyActivity activity;
@Before
public void setup() {
activity = Robolectric.buildActivity(MyActivity.class).get();
}
@Test
public void shouldNotBeNull() {
assertNotNull(activity);
TextView textView = (TextView) activity.findViewById(R.id.myView);
assertNotNull(textView);
}
@Test
public void sent_message_list_item_should_autolink() {
TextView textView = (TextView) activity.findViewById(R.id.myView);
ShadowTextView shadowView = (ShadowTextView)Robolectric.shadowOf(textView);
assertTrue(shadowView. //how to get property autolink here?? )
}
答案 0 :(得分:0)
应该是这样的:
@Test
public void sent_message_list_item_should_autolink() {
TextView textView = (TextView) activity.findViewById(R.id.myView);
assertEquals(Linkify.ALL, textView.getAutolinkMask());
}
还考虑使用一些断言库。我的偏好是Android AssertJ