Last active
June 25, 2019 21:53
-
-
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/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
... | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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