• Delphi2009&2007中,测试工程的初级使用(DUnit)


    Delphi2007之后,编辑器内含了Dunit,要使用它,应该按下面的步骤:

    1.首先准备“被测试工程”

    2.再建立“测试工程”和“项目组工程”。

    3.给“测试工程”添加“测试单元文件”。(选择好“被测单元”后,“测试单元”是自动建立基本测试类的,只需要添加测试代码)

    测试代码中,测试方法是一些以“Check”开头的过程。

    比如:

    “被测单元”如下:

    unit uXXXMath;   
       
    interface   
    uses SysUtils;   
       
    type   
       
    TXXXMath = class   
    public   
      function getSum(const a,b:Integer):Integer;//求和函数   
    end;   
       
    implementation   
       
    { TXXXMath }   
       
    function TXXXMath.getSum(const a, b: Integer): Integer;   
    begin   
      Result := a+b;   
    end;   
       
    end.  

    测试单元时这个样子的:

    unit TestuXXXMath;   
    {  
      
      Delphi DUnit Test Case  
      ----------------------  
      This unit contains a skeleton test case class generated by the Test Case Wizard.  
      Modify the generated code to correctly setup and call the methods from the unit   
      being tested.  
      
    }   
       
    interface   
       
    uses   
      TestFramework, SysUtils, uXXXMath;   
       
    type   
      // Test methods for class TXXXMath   
         
      TestTXXXMath = class(TTestCase)   
      strict private   
        FXXXMath: TXXXMath;   
      public   
        procedure SetUp; override;   
        procedure TearDown; override;   
      published   
        procedure TestgetSum;   
      end;   
       
    implementation   
       
    procedure TestTXXXMath.SetUp;   
    begin   
      FXXXMath := TXXXMath.Create;   
    end;   
       
    procedure TestTXXXMath.TearDown;   
    begin   
      FXXXMath.Free;   
      FXXXMath := nil;   
    end;   
       
    procedure TestTXXXMath.TestgetSum;   
    var   
      ReturnValue: Integer;   
      b: Integer;   
      a: Integer;   
    begin   
      // TODO: Setup method call parameters   
      a := 10;    //我们加上的   
      b := 20;   
      ReturnValue := FXXXMath.getSum(a, b);   
      CheckEquals(a+b,ReturnValue,'结果不对呀!出错了?');//我们加上的   
       
      // TODO: Validate method results   
    end;   
       
    initialization   
      // Register any test cases with the test runner   
      RegisterTest(TestTXXXMath.Suite);   
    end.   

    时间关系,以上举例来自http://blog.csdn.net/xieyunc/article/details/4140575,见谅!

  • 相关阅读:
    dsadsad
    线程池,封装使用,实现控制子线程
    如何能很好地安排好自己的时间?
    中文验证码
    海量数据处理专题(七)——数据库索引及优化
    java tree jtree的使用
    基于Cookie的单点登录(SSO)系统介绍
    急求VS2010的Cookie解决方法
    微软企业库5.0 学习之路系列文章索引
    Net 4.0 Parallel编程(八)Task中的数据共享(中)
  • 原文地址:https://www.cnblogs.com/lizunicon/p/2243629.html
Copyright © 2020-2023  润新知