Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Test Driven Game Development  (Read 995 times)

0 Members and 1 Guest are viewing this topic.
Test Driven Game Development
« on: November 19, 2014, 07:19:14 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 13
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
« Last Edit: November 22, 2014, 06:43:13 pm by AABatteries »
Logged
Re: Test Driven Game Development
« Reply #1 on: November 20, 2014, 01:41:09 am »
  • Personal Saucier
  • *
  • Reputation: +17/-1
  • Offline Offline
  • Posts: 248
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?
Logged
Re: Test Driven Game Development
« Reply #2 on: November 20, 2014, 09:29:02 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 13
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.
« Last Edit: November 20, 2014, 10:19:40 pm by AABatteries »
Logged
Re: Test Driven Game Development
« Reply #3 on: November 22, 2014, 07:37:49 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 13
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
Logged
Pages: [1]   Go Up

 


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



Page created in 0.029 seconds with 23 queries.