views:

1871

answers:

9

Question

How would you go adding automated testing to a game?

I believe you can unit test a lot of the game engine's functionality (networking, object creation, memory management, etc), but is it possible to automate test the actual game itself?

I'm not talking about gameplay elements (like Protoss would beat Zerg in map X), but I'm talking about the interaction between the game and the engine.

Introduction

In game development, the engine is just a platform for the game. You could think of the game engine as an OS and the game as a software the OS would run. The game could be a collection of scripts or an actual subroutine inside the game engine.

Possible Answers

My idea is this:

You would need an engine that is deterministic. This means that given one set of input, the output would be exactly the same. This would inlude the random generator being seeded with the same input.

Then, create a bare-bone level which contains a couple of objects the avatar/user can interact with. Start small and then add objects into the level as more interactions are developed.

Create a script which follows a path (tests pathfinding) and interact with the different objects (store the result or expected behavior). This script would be your automated test. After a certain amount of time (say, one week), run the script along with your engine's unit tests.

A: 

This doesn't really answer your question but I was listening to a podcast on Pex from microsoft which does a similar thing to the solution you're proposing and when I was listening to it I remember thinking that it would be really interesting to see if it would be able to test games. I don't know if it would be able to help you specifically, but perhaps you could take a look at some of the ideas they use and apply it to your unit testing.

lomaxx
A: 

I was listening to a podcast on Pex from microsoft which does a similar thing to the solution you're proposing

I'm downloading the podcast now (This is the link on the site you gave, if this isn't the podcast you are refering to, please give me a link).

MrValdez
+2  A: 

Values are so random within the gameplay aspects of development that it would be a far fetched idea to test for absolute values

But we can test deterministic values. For example, a unit test might have Guybrush Threepwood move toward a door (pathfinding), open the door (use command), fail because he doesn't have a key in his inventory (feedback), pick the door key (pathfinding + inventory management) and then finally opening the door.

All of these paths are deterministic. With this unit test, I can refactor the memory manager and if it somehow broke the inventory management routine, the unit test would fail.

This is just one idea for unit testing in games. I would love to know other ideas, hence, the motivation for this post.

MrValdez
+2  A: 

This post at Games From Within might be relevant/interesting.

Anthony Cramp
The article seems to have been deleted. PO2G looks like a link spam site now :-(
rq
Thanks for raising the flag. PO2G went out of business. However, Noel Llopis moved all the blog content across to his blog at Games From Within. I've updated the links accordingly.
Anthony Cramp
Very, very cool. I like the idea of a -monkey flag.
ojrac
+1  A: 

I did something similar to your idea once and it was very successful, though I suspect it is really more of a system test than a unit test. As you suggest your random number generator must be seeded with the same value, and must produce an identical sequence each time. The game ran on 50hz cycles, so timing was not an issue. I had a system that would record mouse clicks and locations, and used this to manually generate a 'script' which could be replayed to produce the same results. By removing the timing delays and turning off the graphic generation an hour of gameplay could be replicated in a few seconds. The biggest problem was that changes to the game design would invalidate the script.

If your barebones room contained logic that was independent of the general game play then it could work very well. The engine could start up without any ui and start the script as soon as initialisation is complete. Testing for crashing along the way would be simple, but more complex tests such as leaving the characters in the correct positions would be more complex. If the recording of the scripts are simple enough, which they were in my system, then they can be updated very easily, and special scripts to test specialised behavior can be set up very quickly. My system had the added advantage that it could be used during game testing, and the exact sequence of events recorded to make bug fixing easier.

David Sykes
+1  A: 

If you are testing the rendering engine I guess you could render specific test scenes, do a screen captures and compare them to reference test renderings. That way you can detect if changes in the engine breaks anything, visually. You can write similar test for the sound engine, or even animation (by comparing a series of frames).

If you want to test game logic or scene progress you can do this by testing various conditions on the scripting variables (assuming you are using scripting to implement most of the scene and story aspects).

Anders Sandvig
+1  A: 

If you're using XNA (the idea could be extrapolated to other frameworks of course), you could use an in-game unit test framework that lets you access the game's state in the unit test. One such framework is Scurvy.Test :-)

Joel Martinez
+1  A: 

An article from Power of Two Games was mentioned in another answer already, but I suggest reading everything (or nearly everything) there, as they are all really well-written and apply directly to games development. The article on Assert is particularly good. You can also visit their previous website at Games From Within, which has a lot written about Test Driven Development, which is unit testing taken to the extreme.

The Power of Two guys are the ones who implemented UnitCpp, a pretty well-regarded unit testing framework. Personally, I prefer WinUnit.

mos
Might want to change the Power of Two Games links to point to Games From Within. PO2G is no longer hosting meaningful content.
Anthony Cramp
Power of 2 Games wrote UnitTest++, which is available at http://sourceforge.net/projects/unittest-cpp/. It is pretty great.
dash-tom-bang
+1  A: 

http://flea.sourceforge.net/gameTestServer.pdf

This is an interesting discussion on implementing a full-blown functional tester in a game.

The term "unit testing" implies that a "unit" is being tested. This is one thing. If you're doing higher-level testing (e.g. several systems at once), usually this is called functional testing. It is possible to unit test much of a game, however you can't really test for fun.

Determinism isn't necessary, as long as your tests can be fuzzy. E.g. "did the character get hurt" as opposed to "did the character lose 14.7 hitpoints.

dash-tom-bang