NUnit - The Unit Testing Framework
I recently started using the NUnit testing framework with a project at work. This is a reflection based system that can scan through your assemblies and execute specially declared test methods that you have written. This is very useful as you can run repeated tests on your code to make sure nothing gets broken. I think this tool is extremely useful and it has already helped me to track down quite a few bugs.
You can download the testing framework from here. Basically you include the NUnit assembles in your project, and then you create a test class. You prefix the test class with the
[TestFixture] attribute. Then you declare a load of methods of the form 'void MyFunc()'. You then prefix these methods with the [Test] attribute. You can have as many of these methods as you like testing bits of your code. The testing framework provides an Assert class and this has lots of methods like IsTrue, IsFalse, IsEqual etc. You can use these to check the return values from your code. If any of these methods fails, the Test Framework UI will report the errors and you can easily see where something went wrong and fix it. The screen shot below shows a series of tests I have run on a assembly. All the tests have passed in this example, but if one of the green dots turns red, that test has failed.

The following book is a very good book about unit testing with NUnit. Not only does it cover how to setup and use the framework, it also talks about different methods and techniques for testing your code. If you intend on using NUnit, then I seriously recommend you buy this book.




0 Comments:
Post a Comment
<< Home