Is unit testing viable in game programming?

后端 未结 7 1026
-上瘾入骨i
-上瘾入骨i 2021-01-30 01:06

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

7条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-30 01:44

    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.

提交回复
热议问题