• 使用NUnit进行单元测试


    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");
                  }

                  /// <summary>
                  /// SetTest
                  /// </summary>
                  [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");
                  }
           }

    引自:http://blog.csdn.net/davidullua/archive/2005/05/11/373694.aspx

  • 相关阅读:
    采购到入库所经历的表
    PO 收料SQL
    关于PO 和PR 的联系问题
    在Oracle Form中,如何实现自动编号(行号)的功能
    订单暂挂问题sql解决:
    类和结构的区别?
    DataTable.Select 方法 (String, String, DataViewRowState)
    Ref与Out的区别
    C# 反射
    委托
  • 原文地址:https://www.cnblogs.com/kevinlzf/p/705382.html
Copyright © 2020-2023  润新知