Resources > Coding

Test Driven Game Development

(1/1)

AABatteries:
Just thought I'd throw this out there. I've put together a repository to demonstrate.

The idea is that you determine what you want to achieve with a test, write out the scenario you want to test.
Run the test (it should fail).
Write the simplest thing you can to make the test pass.
Write a new test and repeat.

As an example to start off with I've created a simple batch of tests built to test an implementation of link's movement. Someone could then take this and write their own implementation to make the tests pass.

Visual studio 2013 is required.

Running the test runner application will run the tests for you and generate a report.
https://github.com/aabatteries1020/zeldagame

LorentzChronon:
I think this is a really neat idea!
I'm curious as to how it would work for different code-bases. Do the tests require a certain interface or class inheritance?

AABatteries:
You use tests to drive out your design, hence the term test driven game development.

If you have a different code base then your tests will be different because your design will be different. At most what I've put up will give you a decent idea of what you might want to test and potentially how to go about testing it.

If you're trying to write tests in order to test existing code you may find it in some cases to be somewhat difficult, but this is only because the code you currently have is badly designed, it's not modular or reusable.

Some things are more difficult to test than others, for example, in my code I've got an interface called icontrollable, which I mock out in my tests and use as a substitute for keyboard interaction so that the relevant bits of code in my walking engine can be tested. This also has the side effect of having a better design since my movement engine has now been separated from my keyboard logic.

Some of this might make more sense if I were to write the actual code for it to make the tests I've written pass.

edit: I've written the code needed to make the tests pass.

AABatteries:
I've updated the repository bundling the nunit runner so you don't need nunit. When you try and run it will run the tests and generate a report.

I've also decided to go down a more BDD route with my tests, as this makes my tests look a lot cleaner and human readable.

One thing you may notice is that I haven't tried to do anything like loading resources, getting a game window up, getting stuff on screen I'm just concentrating on pure logic. My tests allow me to confidently concentrate on one thing at a time and I'll know if I've introduced a regression bug because one of my tests would fail.

To give an example of the output of my tests:

Story is Entering a moving state  #moving  In order to See the object facing in the right direction in the moving state   As a Gamer   I want Its animation to be set to the direction in which I intend to move       With scenario Object is entering the moving state         Given I intend to move in a direction(Up)Passed        When the object is in the moving statePassed        Then the object is facing in the direction I intended(Up)Passed          And the objects animation is correct for its direction(Up)Passed

Navigation

[0] Message Index


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Go to full version