I\'m fond of the idea of unit testing but I\'m having trouble applying it to game programming. Games are highly stateful and often the code doesn\'t break itself into distinct u
Often the code doesn't break itself into distinct units.
That's just poor design. The code doesn't break itself into anything. You, the designer, have to impose a structure on the code so that you can demonstrate that it actually works.
However, this function will likely return no value...
So?
...and have the side effect of, player.velocity.y = -height
and checkCollisions(player)
.
Then test for that.
I can't think of a clear unit test to build around this.
Why not? You just gave an excellent specification for the results of the function.
You might need a few mock objects to replace the full-blown Player with a simplified MockPlayer that's easier to test with.
But your specification of behavior was perfect. Just test for the things you described.