我有一个扩展的类和ArrayAdapter。当我运行代码时,一切正常,事情发挥作用。但是,当我运行JUnit测试时,我注意到super方法没有正确运行构造函数,并且mObjects(在超类中)没有被设置为对象的值。
无论输入如何,getCount()方法始终返回0。
我需要做些什么才能让它在测试中正常运行?
Java类
public class PlanOfCareCheckBoxAdapter extends ArrayAdapter<String>{
private BiMap<Integer, String> map;
private Set<Integer> mPendingItems, mDoneItems;
private boolean isSuperUser;
public PlanOfCareCheckBoxAdapter(Context context, int resource, List objects, BiMap<Integer, String> mapping) {
super(context, resource, objects);
isSuperUser = false;
mPendingItems = new HashSet<>();
mDoneItems = new HashSet<>();
map = mapping;
}
...
测试
我试图用JUnit
测试它public class PlanOfCareCheckBoxAdapterTest extends AndroidTestCase {
PlanOfCareCheckBoxAdapter mAdapter;
List<String> values;
Context mContext;
public PlanOfCareCheckBoxAdapterTest(){
super();
// mContext = new MockContext().createPackageContext(new CallBellApplication().getPackageName(), MockContext.CONTEXT_INCLUDE_CODE);
mContext = new MockContext();
new POCValues(mContext);
}
@Before
public void setUp() throws Exception {
// super.setUp();
setContext(mContext);
testAndroidTestCaseSetupProperly();
values = new ArrayList<>();
values.add("one");
values.add("two");
values.add("three");
mAdapter = new PlanOfCareCheckBoxAdapter(mContext, 0, values, POCValues.masterMap);
// assertEquals("one", mAdapter.getItem(0));
}