My code is trying to kill me

How do I test the game loop?


In short: you don't.

Tests you write are the game loop. The core elements of the game loop are:

  • read player's input
  • update the game state based on input
  • display the game state

From this three, you only test the middle one.

You can't test the player input or the display (well, you can, but you don't want to). In tests you don't read the player's input, you simulate it. You simulate it by calling functions that will be called when user provide some input. After you call that functions, you check the game state and assert your assumptions about the consequent state. Since game will draw the screen from this very state, you can be sure that it has the correct data to draw.