代码改变世界

VS2008中使用NUnit

2010-08-04 13:14  轩脉刃  阅读(376)  评论(0编辑  收藏  举报

1.下载NUnit:

http://www.nunit.org/index.php?p=home

2.创建测试的project

3.增加Reference(nuit.framework)

4,写测试类(诸如):

 

代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace TestNUnit
{
[TestFixture]
public class NumersFixture
{
private int a;
private int b;

[SetUp]
public void InitializeOperands()
{
a
= 1;
b
= 2;
}

[Test]
public void AddTwoNumbers()
{
int sum = a + b;
Assert.AreEqual(sum,
3);
}

[Test]
public void MultipllyTwoNumbers()
{
int product = a * b;
Assert.AreEqual(
2, product);
}
}
}

 

 

5.在project的properties中设置Debug信息:

 

6.Debug的时候就可以运行NUnit