Software QA FYI - SQAFYI

Unit Testing with NUnit—Creating a Test

By:

Unit Testing with NUnit—Creating a Test

Creating a Test

The following steps outline how to create a solution that contains two projects—a project being tested and an NUnit test project:

1. Open the Visual Studio .NET IDE and create a new blank solution called NPR.

2. Add a new Visual C# class library project called MyApp to the solution. This is the project you’ll be running the tests against.

3. Rename Class1 to MyMath. Change the class declaration to read:

public class MyMath

4. Add a single method called Add that takes two integer arguments and returns their sum. The completed class follows:

using System;
namespace MyApp
{
public class MyMath
{
public int Add(int i, int j)
{
return i + j;
}
}
}


5. Add a new Visual C# class library project called MyAppTest to the solution. This is the project that will contain the NUnit tests. It is a good idea to use a name that allows the test project to be easily identified—for example, use the name of the project being tested with the suffix Test.

WARNING
It is generally best to compile application code and test

code into different assemblies. This makes it easy to build a release executable that does not contain any unit tests.

6. Add a reference to the NUnit framework to the test project MyAppTest; select Project->Add Reference from the Visual Studio .NET IDE menu. In the Add Reference dialog, double-click on nunit.framework in the listbox on the .NET tab and click OK.

Full article...


Other Resource

... to read more articles, visit http://sqa.fyicenter.com/art/

Unit Testing with NUnit—Creating a Test