For .Net programmers, the tool of choice for unit testing is NUnit. For more information about NUnit, see toolkit below.
I recommend creating a project for your unit testing,
To do this, you need to run NUnit's commandline utility, located in NUnit's Program Files folder \bin.
Create your testing class and methods:
[TestFixture]
Class1
{
[Test]
public void Test1()
{
Project1.MyUnit1 minute = new Project1.MyUnit1();
Assert.AreEqual(myUnit.Add(1,2), 3); // assert an exception if 1 + 2 <> 3
}
}
Next, go to the project properties for your NUnit project, click Build Events on the left-hand side. In the Post-build Event Command Line field paste the following:
"%programfiles%\NUnit 2.2\bin\nunit-console" "$(SolutionDir)\Project1.nunit" > "$(SolutionDir)\Project1.nunit.log"
This assumes your .nunit file is in the root of your solution. Variables above might need to be changed to work with your project. Once you build this logic into your solutions, unit testing can become seamless.
No comments:
Post a Comment