テストしたいスタイル可能な属性を持つカスタム android ビューがあります。私は RoboAttributeSet を使用してこれらをビューのコンストラクターにプッシュしようとしていますが、私の人生では、それらを機能させるために使用する必要がある正しい構文を解決できません。何を試しても、Robolectric テスト内で実行しているときに、プッシュしている属性がビューによって取得されません。デバイスまたはエミュレーターでアプリを実行しても問題ありません。
これらをどのように使用するかの例はありますか? 誰もこれを行う方法を知っていますか? カスタム ビューのコード スニペットと、スタイル可能な属性の使用方法を次に示します。
TypedArray customProperties = aContext.getTheme().obtainStyledAttributes(aAttrs, R.styleable.LoginView, 0, 0);
try {
userName.setHint(customProperties.getString(R.styleable.LoginView_username_hint));
} finally {
customProperties.recycle();
}
これは、私の Robolectric/Spock 単体テストのスニペットです...
given:
AttributeSet attributes = new RoboAttributeSet(
[new Attribute("com.acme:attr/username_hint", "myhint", "com.acme")], Robolectric.application.resources, LoginView)
when:
view = new LoginView(Robolectric.application, attributes)
then:
view.getUsername().getHint() == "myhint"
ありがとう
ジョージ