当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 使用NUnit进行单元测试

ASP.NET
URTracker 2.11版 license验证原理剖析
使用DataReader还是DataSet?
XCodeFactory 强化静态检查!
[DNN模块开发]如何写模块数据库安装脚本
C#中数据库操作
.NET和SQL Server中“空值”辨析
用 .NET 实现插件机制
如何用MAPI和CDONTS来发邮件
VB6 中使用错误处理对于速度的影响
基于XMPP的JABBERD功能特性分析
我在使用C#中Treeview与解析XML遇到的问题
使aspx页面能接受HTML,asp的页面传送的文件
顺序求出c(n,r)的排列组合
asp.net生成静态页
根据数据库生成xml二法
Render方法生成静态页
用ASP.Net获取客户端网卡的MAC
缓存类的实现(C#)
r.a.d.controls Q2 2005中TreeView 控件遮挡问题
为按钮添加 确认 对话框

ASP.NET 中的 使用NUnit进行单元测试


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 225 ::
收藏到网摘: n/a


NUnit适用于.Net开发中的单元测试,使用步骤如下
1、下载NUnit-2.2.2并解压或安装。
2、VS.Net中建立 项目,添加对NUnit.Framework.dll的引用,
3、创建新类AccountTest 测试已存在的类Account
4、将代码编译为DLL或exe文件,在nunit-gui主程序中打开编译过的程序,选中要运行的Test Case点Run
另外,配合DCGWin,可将NUnit的测试结果(保存的XML文件)生成html格式的测试报告.
public class Account { private float balance;
public void Deposit(float amount) { balance += amount; }
public void Withdraw(float amount) { balance -= amount; }
public void TransferFunds(Account destination, float amount) { this.balance-=amount; destination.balance+=amount; }
public float Balance { get { return balance; } set { balance=value; } } }
[TestFixture(Description="帐号测试")] public class AccountTest {
[Test(Description="转帐测试")] public void TransferFunds() { Account source = new Account(); source.Deposit(200.00F); Account destination = new Account(); destination.Deposit(150.00F);
source.TransferFunds(destination, 100.00F); Assert.AreEqual(250.00F, destination.Balance);//should be 250 Assert.AreEqual(100.00F, source.Balance); Console.WriteLine("Funds Tranfer Event Tested Successfully"); }

[Test(Description="Account.Balance的Get属性")] public void GetTest() { Account source=new Account(); source.Deposit(100.00F); Assert.AreEqual(100,source.Balance); Console.WriteLine("Balance Attributes Get Tested Successfully"); }
/// /// SetTest /// [Test(Description="Account.Balance的set属性测试")] public void SetTest() { Account source=new Account(); source.Balance=100; Assert.AreEqual(100,source.Balance); source.Balance-=50; Console.WriteLine("Balance Attributes Set Tested Successfully"); Assert.AreEqual(50,source.Balance);
}
[Test(Description="取款测试")] public void WithDrawTest() { Account source=new Account(); source.Deposit(100.00F); source.Withdraw(20.00F); Assert.AreEqual(80,source.Balance); Console.WriteLine("Balance Attributes WithDraw Tested Successfully"); }
[Test(Description="存款测试")] public void DepositTest() { Account source=new Account(); source.Deposit(100.00F); Assert.AreEqual(100,source.Balance); Console.WriteLine("Balance Attributes Deposit Tested Successfully"); } }