Home :: News ::
Defeat in Detail: Unit tests and SpecsFor
|13th, November 2011|
For the new game I am creating I will be using Unit Tests extensively (unlike other project I have/am working on…cough) and with this many different methodologies follow just for testing code. When I come to create new code in the game I will be performing TDD (Test Driven Development) which means testing/creating test cases as you code and not as an afterthought. Currently I am using code I have created for a test app, and thus I am backtracking all missed unit tests – AND NO NEW CODE WILL BE WRITTEN until I have 100% (or as close to) coverage of public methods in my codebase.
To do this, I am using NUnit, MOQ via SpecsFor; SpecsFor is a free framework for testing methods using a Behaviour-Driven Development methodology (e.g. Given
Also, SpecsFor automatically creates mock objects through StructureMap and means you can track how the current class is interfacing with other objects easily and in a standard.
"Wow, this all sounds great, but what are the drawbacks?" - the only drawback for SpecsFor is the learning curve, getting your head around what is happening can take a few moments (especially with the limited documentation on the website) but if you watch the following videos then you will start to understand.
Here is an example of a test in my PathFindingInfo class; this class holds and processes the current target and step in path finding (step: where to move NOW and target: the final destination):
This test reuses the [Given] class (a_target_has_been_set) on all of the [Test]s – this means we have fresh objects every time. Now, the best way to read these tests is via the names given, here is an example:
As you can see, each part that builds the test increases the descriptive structure of the inputs and outputs of the tests - VERY NICE :)
Once I have started playing with Mocks then I will post my findings, as for now I am unit testing all my existing code (thank god for re-usable code).
I would like to thank the creator of the SpecsFor system Matt Honeycutt for all brilliant work he has done and released online – please visit his blog for more info on this and much much more at http://trycatchfail.com/
|0 Comments||Posted by Simon Colmer|
No comments found
Add a comment
Top viewed media
1. Glastonbrooke 11 - That Chiboa 2007
2. If Humans Tasted Good
3. LILT Bloopers
4. Two Lovies and Steve
5. What She Read Last Friday
GitHub | Twitter | Facebook
X-Volt Studios, Copyright 2009. ©