Game development, by nature, is complex and has many specialized disciplines:
|
Consequently, the task of coding and testing game components in isolation can be very challenging due to the tightly coupled nature of these dependencies.
Example
Asteroids: in this simple game, the player controls a spaceship depending on input from the controller.
In order to test the spaceship's rotate and move methods in isolation, the external dependency on the controller must be broken.
Dependency Injection and Inversion of Control (IoC)
When an object instantiates another object that it depends on then this leads to poor design because it promotes tight coupling between the objects. Tightly coupled code cannot be changed easily without consequences: changes made to one object may cause other objects to break.
A better approach is to break dependencies between objects and promote loose coupling:
Loose coupling leads to better design as the software is less likely to break.
Dependency Injection is a simple pattern to loosely couple objects and break their dependencies.
The resulting design principle, Dependency Inversion, states: Depend upon abstractions.
Do not depend upon concrete classes.
By coupling an object to an interface instead of a specific concrete implementation, you have the ability to use any implementation with minimal change and risk. This concept is important, especially when testing an object in isolation (unit testing).
Inversion of Control (IoC) is a framework characteristic whereby objects, which depend on other objects, do not need to instantiate those objects; instead they get the objects they need from an external source.
IoC Container
An IoC Container is a framework component that automatically resolves all dependent references for an object: when an object is constructed, the container will instantiate all dependent objects automatically and injects them into the source object accordingly.
There are many IoC containers available to .NET developers:
Unit Testing
Unit testing is the practice in which individual units of source code are tested in isolation. Consequently, unit tests do not measure how objects interact with dependent objects; these are integration tests.
In order to successfully unit test an individual game component, external dependencies are broken, and replaced by mock objects: fake objects that emulate real classes and help test expectations about how that class should function.
Therefore, clean unit tests should be written F.I.R.S.T:
Fast Independent Repeatable Self-validating Timely | Tests should be fast Tests should not depend on each other Tests should be repeatable in any environment Tests should have a Boolean output: either they pass or fail Tests should be written in a timely fashion |
Test Driven Development (TDD)
Test driven development (TDD) is similar to unit testing except the unit tests are written before the objects they test. TDD is gaining as a development best practice because objects are designed with testability in mind: an object and its dependencies must be loosely coupled from the outset.
TDD practitioners follow these three laws:
First Law: Second Law: Third Law: | You may not write production code unless you’ve first written a failing unit test You may not write more of a unit test than is sufficient to fail You may not write more production code than is sufficient to make the failing unit test pass |
Extreme Programming
Extreme Programming is a method of agile software development which advocates frequent releases with short development cycles. The focus on delivering business value within each iteration leads to increased quality and lower overall total cost.
Therefore, it seems only relevant to try and integrate agile methodologies into XNA game development. As an exercise, I would like to prototype the following agile techniques accordingly:
5 comments:
Hi,
nice, concise post. I'm going to forward it to my students. In our student projects, we actually use (a slightly adapted version of) Scrum as agile development method with XNA as underlying development technology. We achieve very good overall results during these courses with full playable games. However, we notice that students really struggle with Scrum, or more general, with the agile approach, especially during the first weeks.
These problems show up as issues in code quality in the end and it is hard to install a "testing sprint" or "iterative refactoring" as counter measure. What do you think, could TDD or XP do better than Scrum in this context?
Hi Robert,
Thanks for your feedback and to forward this post onto your students is very much appreciated!
I tend to think of SCRUM as an iterative incremental framework for managing complex work.
Whereas, TDD as an agile approach to software engineering - very popular aspect of XP.
Therefore, I don't think comparing TDD or XP to SCRUM is really comparing apples to apples:
SCRUM is a process that breaks backlog items into tasks that are completed during the sprint.
Whereas TDD is an approach to software engineering in which unit tests are written first.
Cheers,
Steve.
Hi there, awesome site. I thought the topics you posted on were very interesting.
I tried to add your RSS to my feed reader and it a few. take a look at it, hopefully I can add you and follow.
Agile Software Development
Hi Sorna,
Thanks for your feedback. I use Feed Burner so the RSS should work ok.
Cheers,
Steve.
Hi Arumugam,
Thanks very much for your feedback and linking this article to your Facebook account; this is very much appreciated.
Cheers,
Steve.
Post a Comment