Wednesday, March 4, 2009

NUnit versus Visual Studio 2008's Test Project for Unit Testing on C# codes

I've seen people asking about which unit test tool to use and would like to talk about my experience with NUnit and Visual Studio 2008.I started unit testing with NUnit and loved it and the idea of unit testing. The good things about it are:
It is easy to get started.
It has a very good user interface, simple but elegant. It shows everything you will want to see from unit test results.
It runs fast.
Tests can be run from inside Visual Studio so you can debug the codes if needed. I know it can plug into Visual Studio but never tried that. The way I use it is to set my unit test project's Start Up application as NUnit.exe in the project's debug configuration.
Tests can also be run by using NUnit's UI only if you want to see some quick results.When I started using Visual Studio 2008, I noticed that in the Add an item menu, there is an option to add a Unit Test. I started to try it. At the beginning, I still prefer NUnit. But now I would recommend people to use Visual Studio 2008's unit test for the following reasons:
VS's unit test codes can be generated automatically. This saves a lot of typing. It's not a big deal though if you want to organize the codes in your own way. But it is a very powerful and impressive feature.
VS's unit test allows you to test private functions. This is something I wished NUnit would have when I was using NUnit. There are simply some important private functions that need to be covered with Unit Test. I don't want to change them to public in order to test them.
The most compelling reason that I want to stick with VS unit test is that these tests can by used by Team System's load test directly. I recently started working on load testing with Team System. It is very powerful load testing tool. It can be created by selecting unit tests or web tests. If the codes being tested are for a server and load is a concern, it is better to create VS unit tests so they can be used for load tests later.It is possible to use both though by using some conditional compiling settings. But I feel it will be easier to deal with one tool only.

No comments:

Post a Comment