Add unit tests
SoniEx2 opened this issue ยท 9 comments
Dream on, Soni. Dream on.
Minecraft has no testing framework for us to utilize.
To unittest inventories is pretty simple:
List<IInventory> allInvs = new ArrayList<IInventory>();
public void init() {
IInventory myInventory = new MyInventory();
allInvs.add(myInventory);
// repeat for the other invs
}
public void testGetStackInSlotOnClosing() {
// fill invs
for (IInventory inv : allInvs) {
for (int i = 0, j = inv.getSizeInventory(); i<j; i++) {
inv.setInventorySlotContents(i, new ItemStack(...)); // put something here
}
}
// test
for (IInventory inv : allInvs) {
for (int i = 0, j = inv.getSizeInventory(); i<j; i++) {
ItemStack expected = inv.getStackInSlot(i);
ItemStack got = inv.getStackInSlotOnClosing(i);
if (expected != got) throw new RuntimeException();
if (inv.getStackInSlot(i) != null) throw new RuntimeException();
}
}
}
(Not the actual code you'd use but it gives you an idea)