Nunit使用手记


1.       首先下载Nunit2.4.1http://xiazai.zol.com.cn/detail/27/264331.shtml#down

2.       然后下载Resharperhttp://kb.cnblogs.com/a/1441816/,是一个Vs.NET的插件,下载后安装,注册。用来执行自己写的测试类。

3.       新建测试工程Test,测试项目中业务逻辑类tbl_Account中的一个方法

/// <summary>

         /// 增加一条数据

         /// </summary>

         public int Add(TPMS.Model.tbl_Account model)

         {

              return dal.Add(model);

         }

4.      编写测试类:

namespace Test

{

    [TestFixture]

    public class AccountAddTest

    {

        [Test]

        public void Add()

        {

            BLL.tbl_Account bll = new BLL.tbl_Account();

            Model.tbl_Account account = new Model.tbl_Account();

            account.PerName = "abc";

            account.LoginName = "abc";

            account.LoginPwd = "abc";

            account.PerCode = 10;

            account.undefine4 = "0";

            account.undefine5 = "";

            int id = bll.Add(account);

 

            Assert.AreEqual(12, id);

 

        }

    }

}

5.在VS.NET中执行Debug Unit Tests

 

原文地址:https://www.cnblogs.com/blsong/p/1638830.html