Around 2 days ago, I have just tried to use NUnit. NUnit is software used to do unit testing during software development in C# ASP.NET environment. At first, it took quite a while (around 1-2 hours) just to figure out, install and learn how to use this software.
This is my first time using unit testing tool because in my previous job, a lack of documentation on system workflow always prevented me to create well defined test cases and its expected results. Here, the new developer has done excellent job on documenting the workflow and made my job is easier (I am using version 2.6.1 on Visual Studio 2010 on Windows 8, btw).
And then come first obstacle after installation. I encountered error alert box popped up when I try to load my DLL project file into newly created NUnit project. The error said: “This assembly was not build by any known testing framework“. After minutes of browsing on stackoverflow and couples of forum, it turned out that I need to go to the Tools -> Settings -> IDE Support -> Visual Studio and check the option: “Enable Visual Studio support” as indicated in figure below:
After that, you can load the DLL file to NUnit project. However, at this moment, I confused because it turned out the graphical appearance for my project is quite different from the sample project in the bundled NUnit software. The sample project has a look of apparently some classes together with its methods and a set of test cases to be executed upon clicking ‘Run’ button at the main interface:
In contrast, my DLL project did not have tick and cross icons and no public methods which were defined inside those DLL project were visible from this NUnit GUI screen. It turned out that we need to incorporate NUnit library (nunit.framework.dll) located inside bin folder of NUnit program into our Visual Studio project. You can right click and choose ‘Add reference…’ in Solution Explorer window and browse that DLL file inside NUnit installation path.
After that you can test your methods which are contained inside code behind file. First, just add NUnit.Framework namespace and then use [TestCase] statement above the methods which you want to test as shown below:
After that, I compiled my class library project and then I reopened the NUnit project and viola, the test is working now: