<p><strong>Question</strong></p>

<p>How would you go adding automated testing to a game?</p>

<p>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?</p>

<p>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.</p>

<p><strong>Introduction</strong></p>

<p>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.</p>

<p><strong>Possible Answers</strong></p>

<p>My idea is this: </p>

<p>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.</p>

<p>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.</p>

<p>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.</p>

[{'answer_id': 14136, 'author': 'lomaxx', 'author_id': 493, 'author_profile': 'https://Stackoverflow.com/users/493', 'pm_score': 0, 'selected': False, 'text': '<p>This doesn\'t really answer your question but I was listening to a podcast on <a href="http://research.microsoft.com/pex/" rel="nofollow noreferrer">Pex from microsoft</a> 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.</p>\n'}, {'answer_id': 14181, 'author': 'MrValdez', 'author_id': 1599, 'author_profile': 'https://Stackoverflow.com/users/1599', 'pm_score': 2, 'selected': False, 'text': "<blockquote>\n  <p>Values are so random within the gameplay aspects of development that it would be a far fetched idea to test for absolute values</p>\n</blockquote>\n\n<p>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.</p>\n\n<p>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.</p>\n\n<p>This is just one idea for unit testing in games. I would love to know other ideas, hence, the motivation for this post.</p>\n"}, {'answer_id': 14233, 'author': 'Anthony Cramp', 'author_id': 488, 'author_profile': 'https://Stackoverflow.com/users/488', 'pm_score': 3, 'selected': False, 'text': '<p><a href="http://gamesfromwithin.com/?p=97" rel="noreferrer">This post</a> at <a href="http://gamesfromwithin.com" rel="noreferrer">Games From Within</a> might be relevant/interesting. </p>\n'}, {'answer_id': 14270, 'author': 'David Sykes', 'author_id': 259, 'author_profile': 'https://Stackoverflow.com/users/259', 'pm_score': 2, 'selected': False, 'text': "<p>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.\nThe 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.\nThe biggest problem was that changes to the game design would invalidate the script.</p>\n\n<p>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.</p>\n"}, {'answer_id': 14345, 'author': 'Anders Sandvig', 'author_id': 1709, 'author_profile': 'https://Stackoverflow.com/users/1709', 'pm_score': 1, 'selected': False, 'text': '<p>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).</p>\n\n<p>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).</p>\n'}, {'answer_id': 63097, 'author': 'Joel Martinez', 'author_id': 5416, 'author_profile': 'https://Stackoverflow.com/users/5416', 'pm_score': 1, 'selected': False, 'text': '<p>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 <a href="http://www.codeplex.com/ScurvyTest" rel="nofollow noreferrer">Scurvy.Test</a> :-)</p>\n'}, {'answer_id': 66941, 'author': 'moswald', 'author_id': 8368, 'author_profile': 'https://Stackoverflow.com/users/8368', 'pm_score': 2, 'selected': False, 'text': '<p>An article from <a href="http://www.gamesfromwithin.com/" rel="nofollow noreferrer"><s>Power of Two Games</s>Games From Within</a> 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 <a href="http://gamesfromwithin.com/asserting-oneself" rel="nofollow noreferrer">article on Assert</a> is particularly good.  You can also visit their previous website at <a href="http://www.gamesfromwithin.com/" rel="nofollow noreferrer">Games From Within</a>, which has a lot written about <a href="http://www.gamesfromwithin.com/articles/cat_testdriven_development.html" rel="nofollow noreferrer">Test Driven Development</a>, which is unit testing taken to the extreme.</p>\n\n<p>The Power of Two guys are the ones who implemented UnitCpp, a pretty well-regarded unit testing framework.  <a href="https://stackoverflow.com/questions/3150/how-to-set-up-unit-testing-for-visual-studio-c#64482">Personally, I prefer WinUnit</a>.</p>\n'}, {'answer_id': 1203140, 'author': 'dash-tom-bang', 'author_id': 65845, 'author_profile': 'https://Stackoverflow.com/users/65845', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://flea.sourceforge.net/gameTestServer.pdf" rel="nofollow noreferrer">http://flea.sourceforge.net/gameTestServer.pdf</a></p>\n\n<p>This is an interesting discussion on implementing a full-blown functional tester in a game.</p>\n\n<p>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.</p>\n\n<p>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. </p>\n'}, {'answer_id': 25229468, 'author': 'Schifty', 'author_id': 1055796, 'author_profile': 'https://Stackoverflow.com/users/1055796', 'pm_score': 1, 'selected': False, 'text': '<p>I have written a paper on that topic - \n<a href="http://download.springer.com/static/pdf/722/art%253A10.7603%252Fs40601-013-0010-4.pdf?auth66=1407852969_87bc2e71ad5228b36738f0237084ebe5&amp;ext=.pdf" rel="nofollow">http://download.springer.com/static/pdf/722/art%253A10.7603%252Fs40601-013-0010-4.pdf?auth66=1407852969_87bc2e71ad5228b36738f0237084ebe5&amp;ext=.pdf</a></p>\n'}, {'answer_id': 36975921, 'author': 'MrValdez', 'author_id': 1599, 'author_profile': 'https://Stackoverflow.com/users/1599', 'pm_score': 2, 'selected': False, 'text': '<p>Riot Games has an <a href="https://engineering.riotgames.com/news/automated-testing-league-legends" rel="nofollow">article</a> on using automated testing for League of Legends (LoL), a multiplayer online RTS game.</p>\n\n<p>According to the developers, there are many changes to both the game code and game balance everyday. They built a Python test framework that is basically a simpler game client that sends commands to the Continuous Integration server that is running an instance of LoL\'s game server. The server then send the test framework the effect of the command, allowing the response to be tested.</p>\n\n<p>The framework provides an event queue that records the events, data, and effect from a particular point in time. The article calls this a "snapshot".</p>\n\n<p>The article described an example of a unittest for a spell:  </p>\n\n<hr>\n\n<p><strong>Setup</strong><br>\n1. Give a character the ability.<br>\n2. Spawn an enemy character in the midlane (a location on the map).<br>\n3. Spawn a creep in the midlane. (In the context of LoL, creeps are weak non-controllable characters that are part of each team\'s army. They are basically canon fodder and is a source of experience and gold for the enemy team. But if left unchecked, they can overwhelm the opposing team)\n4. Teleport the character to the midlane.</p>\n\n<p><strong>Execute</strong><br>\n1. Take a snapshot of all the variables (e.g. the current life from the player, enemy and normal characters).<br>\n2. Cast the spell.<br>\n3. Activate the spell\'s effects (for example, there are some spells that will proc on hit) on an enemy character.<br>\n4. Reset the spell\'s cooldown so it can be cast again immediately.<br>\n5. Cast the spell.<br>\n6. Activate the spell\'s effects on a creep (in the context of LoL, most spells have different calculations when used on creeps).\n7. Take another snapshot.</p>\n\n<p><strong>Verify</strong><br>\nStarting from the first snapshot, replay the events, and assert that the expected results (from a game designer\'s point of view) are correct. Examples of events that can be verified are: The damage is within the range of the spell\'s damage (LoL uses random numbers to give variance to attacks), Damage is properly resisted when compared with a player character and a creep, and spells are cast within its effective range.</p>\n\n<hr>\n\n<p>The article shows that a video of the test can be extracted when the test server is viewed from a normal game client.</p>\n'}]
['https://Stackoverflow.com/questions/14087', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1599/']