Well yeah; unit tests may be overkill but i write them just for exercise. For example a test which checks that a trigger is activated after the player left the tile and reenters:
@Test
public void shouldTriggerIfPlayerStartsThereButMovesBackAndForth() {
Game testGame = Game.newGame(database, new GameBuilderTestImplementation(false, 0));
Entity player = testGame.getPlayer();
CustomController controller = new CustomController();
controller.addAction(new IdleAction());
controller.addAction(new MoveAction(-1, 0));
controller.addAction(new MoveAction(1, 0));
player.setController(controller);
LocationTrigger toAdd = new LocationTrigger(testGame);
toAdd.setLocation(new Point(2, 1));
toAdd.setActivateCallback(new ActivateCallbackImplementation());
testGame.getCurrentZone().addTrigger(toAdd);
testGame.getLoop().rebuild();
while (testGame.step())
;
Assert.assertEquals(true, wasTriggered);
}
They are somewhat essential for persistence because i simply have a unitttest which checks that gamestates are equal after saving/loading. And running a predefined scenario in less then 10ms is worth it instead of manually proving that everything works.
@Test
public void shouldBeTheSameGame() throws SQLException {
database.getDatabase().open();
// given
Game toStore = Game.newGame(database, new GameBuilderTestImplementation());
BaseEntity player = toStore.getPlayer();
// when
Game.saveGame(toStore, database);
Game reloaded = Game.loadGame(database, null);
database.getDatabase().close();
// then
Assert.assertEquals(player.getId(), reloaded.getPlayer().getId());
Assert.assertEquals(player, reloaded.getPlayer());
reloaded.testCompareTo(toStore);
}
A neat way to make sure that compatibility and upgrade path for save games work.