Skip to content

Instantly share code, notes, and snippets.

@ProGM
Last active June 25, 2019 21:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ProGM/73d6b99a024e8e49ce90f47c6abd4d98 to your computer and use it in GitHub Desktop.
Save ProGM/73d6b99a024e8e49ce90f47c6abd4d98 to your computer and use it in GitHub Desktop.
Automated Testing (TDD/BDD/E2E) in game development https://elfgames.com/2019/06/25/automated-testing-in-video-games-a-case-study/
<?xml version="1.0" encoding="UTF-8"?>
<document>
<steps>
<wait>5</wait>
<press>SkipIntro</press>
<wait>3</wait>
<press>Menu/Settings</press>
<wait>3</wait>
<press>SettingsTab/Options</press>
...
<move>0,-9.67</move>
<skip-dialogues />
</steps>
</document>
public class E2ETestRunner : MonoBehavior {
TestingInputHandler inputHandler = new TestingInputHandler();
void Awake() {
DontDestroyOnLoad(this);
}
public void RunTesting() {
InputModule.ReplaceInput(inputHandler); // Use your fake input module
var xmlFile = Resource.Load<TextAsset>("BDD-steps.xml"); // Load your testing suite
xml = __PARSE_XML__(xmlFile); // Parse xml
StartCoroutine(RunTestingRoutine(xml.SelectNodes("//step"))); // Starting the suite
}
IEnumerator RunTestingRoutine(XmlNodeList steps) {
foreach (var step in steps) {
CheckBugs(); // This method implements some generic checks, like finding Messages overflowing the canvas or exceptions in the console.
switch (step.name) {
case "click":
__IMPLEMENTATION__;
// i.e. Game.Find(step.InnerText).SendMessage("OnMouseDown");
break;
case "move":
__IMPLEMENTATION__;
break;
case "wait":
__IMPLEMENTATION__;
// i.e. yield return new WaitForSeconds(float.Parse(step.InnerText));
break;
...
}
}
}
}
interface InputHandlerInterface {
bool SubmitPressed();
bool CancelPressed();
...
Vector2 GetMovement();
}
public class RealInputHandler : InputHandlerInterface {
____ REAL IMPLEMENTATION THAT USES REAL INPUTS ____
}
public class TestingInputHandler : InputHandlerInterface {
____ FAKE IMPLEMENTATION, Controlled by the E2ETestRunner _____
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment