Robolectric は初めてで、カスタム ボタンのテキストをテストしようとしています。私のカスタム ボタンは、Button と ProgressBar から構成される RelativeLayout です。アプリケーションを実行すると、カスタム属性のテキストがボタンに正しく設定されます。しかし、Robolectric を使用すると、テキストが null になります。
Robolectric TypedArray getString() は null または空の文字列を返しますが、ShadowTypedArray の使用方法に関する情報はほとんどありません。
Robolectric サイトから、彼らは次
のように述べています。
you would annotate the test in question with @Config(shadows={MyShadowBitmap.class})
しかし、これは私にはうまくいきません:
@Test
@Config(shadows={ShadowTypedArray.class})
public void testLoginButton_shouldDisplayLoginText() throws Exception {
Activity activity = Robolectric.buildActivity(LoginActivity.class).create().get();
CustomProgressButton loginButton = (CustomProgressButton ) activity.findViewById(R.id.sign_in_button);
String loginText = loginButton != null ? Strings.toString(loginButton.getText()) : null;
assertThat(loginText, equalTo(activity.getString(R.string.action_sign_in_short)));
assertThat(loginText, equalTo("LOG IN"));
}
ShadowCustomProgressButton を作成する必要がありますか、それとも間違っていますか? ありがとう。