Tuesday, November 15, 2005

Unit testing fun

Getting nunit to work with visual studio 2005 is a bit of problem. It's spits out sometype of invalid file error.

You have to go into the config.exe and in the startup tag there are a number of different .net version - every single one was older than my latest version. So I deleted them all and put in the latest number - which required some searching around.

nunit-gui.exe.config



Looks like so:

<?xml version="1.0" encoding="Windows-1252"?>
<configuration>

<startup>
<supportedruntime version="v2.0.50727">


</startup>


</configuration>




Then it all worked rather nicely and test-first I built up a nice new class to go into my Conversation engine. The scroll bar also now displays properly. Anything where you have to hold the mouse button down currently doesn't work but its getting there.

My super tip for nunit is have your main project in one class library (a dll) then create a new class library called tests (or something equally inspired). Go to references add a reference, then click on the project tab and add your first dll where your main project is. Thereby allowing your test library to have access to your main programs classes! Now all your tests are in a totally seperate piece of code. For the coup de la resistance. Go to the test solution properties and add a post build command that loads nunit.

On Succesful build "nunit /run" should do it. I made the nunit bin directory a system variable. (I did this with lua and python to so I can call them anywhere from the command line. I remember in dos this was rather in easy, the path command or something in autoexec.bat? Anywhoo in window go to control panel. Double click system. Click on the advanced tab. Then click on the environmental varaibles button at the bottom. There's a box called System Variables, in the box is a list box, double click on the one labelled PATH. Then append the following to the string ;C:\Program Files\NUnit 2.2.2\bin. All path's are colon seperated. If you fire up a dos box and type nunit-gui or nunit-console it will run the program.)

Read more about unit testing!

Test-Driven C#: Improve the Design and Flexibility of Your Project with Extreme Programming Techniques -- MSDN Magazine, April 2004


Games From Within Tutorials - excellent resource for nunit test advice - what tests to write and why
Test-Driven Game Development (Part 1)
Test-Driven Game Development (Part 2)
Test-Driven Game Development (Part 3)

No comments: