Game Development Reference
Figure 17.11 Screenshot compare list for failed Minesweepertest.
Minesweeper Test Modularity and Reuse
Isn't it annoying that you have to manually reset the Minesweeper game back to its ini-
tial state after running each automated test? You will waste time if you re-run the test
and forget to reset and close the game. If many tests need to be run in sequence, the
manual activity time would add up and defeat the whole purpose of automation. A
way to deal with this is to automatically return the game to the proper state after you
run each test. You could add a chunk of code at the end of every test, but a more efficient
solution is to create a separate module that performs the cleanup. That module would
get called by each of your Minesweeper tests. This approach costs only one additional
line per test to call the cleanup routine.
The steps you need to implement in the cleanup module are as follows:
1. Click OK to close the custom options window that was left open at the end
of the original test (see Figure 17.10).
2. Activate the Minesweeper window.
3. Select the Game options and click Beginner.
4. Close the Minesweeper window.
This is a good situation in which to use a LogComment statement at the beginning of the
module. It will leave behind a textual note in the log file to explain what is happening.