如何在 TestView 中测试属性 android:autoLink
How to test property android:autoLink in TestView
需要测试属性是否已设置,如何使用 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?? )
}
应该是这样的:
@Test
public void sent_message_list_item_should_autolink() {
TextView textView = (TextView) activity.findViewById(R.id.myView);
assertEquals(Linkify.ALL, textView.getAutolinkMask());
}
也考虑使用一些断言库。我的偏好是 Android AssertJ
需要测试属性是否已设置,如何使用 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?? )
}
应该是这样的:
@Test
public void sent_message_list_item_should_autolink() {
TextView textView = (TextView) activity.findViewById(R.id.myView);
assertEquals(Linkify.ALL, textView.getAutolinkMask());
}
也考虑使用一些断言库。我的偏好是 Android AssertJ