【发布时间】:2016-03-17 22:15:37
【问题描述】:
我有一个动态创建视图的自定义视图。
public class MyCustomView extends LinearLayout {
...
private View foo() {
View view = new View(getContext());
view.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.gray));
return view;
}
}
当我测试 foo() 时,我得到一个资源未找到异常。
public class MyCustomViewTest extends InstrumentationTestCase {
...
public void testFoo() {
View view = myCustomView.foo();
assertNotNull(view);
}
}
android.content.res.Resources$NotFoundException: Resource ID #0x7f0c0022
如何获得测试以查看我的颜色资源?
【问题讨论】:
标签: android android-custom-view android-instrumentation