Testing a Text Adventure

Testing is an important component of any software project, and games are no exception. Javascript is easy enough to unit test for core functionality, but the genre of SRPG offers an interesting opportunity for automated game-aware testing.

All input in the game is simply text, and the game engine already has an ‘input queue’ capable of handling multiple commands in sequence. This feature is already being used for one simple test process, to get me back to a particular state in the game after making changes. It can be taken further, however.

Random events in SRPG are handled with a seeded random number generator, meaning that given the same seed and same inputs, all random effects in the game will happen in the same way. That means I can save a transcript (sequence of inputs) and a seed, then play them back and check the output. This is a natural place to automate tests.

My current plan is to develop tests that specify:

  • Starting state (optional, used to shortcut to later portions of the game before testing something specific)
  • Random seed
  • Input sequence
  • Test callback

If/when the input sequence concludes, the callback is run to check for certain elements. For example, checking the last text output, or looking at an attribute of a particular object.

Helpful tests could include:

  • Intro process works (race/class selection)
  • Movement works (starting area)
  • Checking inventory works

During each build, I can run all the tests to get an idea of the health of the game code, and find out immediately if my most recent changes have broken anything.