我有一个自定义的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();
}
Run Code Online (Sandbox Code Playgroud)
这是我的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"
Run Code Online (Sandbox Code Playgroud)
感谢
乔治