1.新建.NET工程;
2.添加NUnit的引用:
1)
2)
3.为工程要测试的类或函数增加相应的UNnit标记;
namespace NUnitQuiteStart
{
[TestFixture]
public class NumbersFixture
{
[Test]
public void AddTwoNumbers()
{
int a = 1;
int b = 2;
int sum = a + b;
Assert.AreEqual(4, sum, "if there is 4,it is right");
}
}
}
注:在文件开头要增加using NUnit.Framework;
4. 设置NUnit为程序的开始:
1)选择工程的属性
2)设置程序的开始执行程序
5.在.NET中点击运行,则会自动启动NUnit;
6.在Nunit中点击RUN,运行测试;
注:NUnit中的测试结果,绿色代表通过,红色代表不通过。