我如何组合这个构造函数?
private Item[] items;
private int currentIndex;
/**
* Default Constructor
*/
public Inventory()
{
this.items = new Item[1];
this.currentIndex = 0;
}
答案 0 :(得分:-1)
将非公开测试成员和字段包私有化是标准做法。像这样,
Item[] items;
int currentIndex;
public Inventory()
{
this.items = new Item[1];
this.currentIndex = 0;
}
现在,只要单元测试与Inventory
类在同一个包中,
public void testCtor() {
Inventory i = new Inventory();
assertNotNull(i.items);
assertEqual(1, i.items.length);
assertEqual(0, i.currentIndex);
}