CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  VCL组件开发及应用

DUnit的原理是什么,如何来测试单元??

楼主jbmaster()2005-08-03 18:25:08 在 Delphi / VCL组件开发及应用 提问

unit   BeTestUnit;  
   
  interface  
   
  uses  
      Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,  
      Dialogs;  
   
  type  
      TBeTestForm   =   class(TForm)  
      private  
          {   Private   declarations   }  
      public  
          {   Public   declarations   }  
          function   BeTestFunction(I,   J:   Integer):   Integer;  
      end;  
   
  var  
      BeTestForm:   TBeTestForm;  
   
  implementation  
   
  {$R   *.dfm}  
   
  {   TBeTestForm   }  
   
  function   TBeTestForm.BeTestFunction(I,   J:   Integer):   Integer;  
  begin  
      Result   :=   I   *   J;  
  end;  
   
  end.  
   
  --------------------------------------------------------------------------  
   
  unit   TestUnit;  
   
  interface  
   
  uses  
      TestFrameWork,   BeTestUnit,   Dialogs;  
   
  type  
      TTestCaseFirst   =   class(TTestCase)  
      private  
          BeTestForm:   TBeTestForm;  
      protected  
          procedure   SetUp;   override;  
          procedure   TearDown;   override;  
      published  
          procedure   TestFirst;  
          procedure   TestSecond;  
      end;  
   
      TTestCaseSecond   =   class(TTestCase)  
      published  
          procedure   TestThird;  
      end;  
   
  implementation  
   
  {   TTestCaseFirst   }  
   
  procedure   TTestCaseFirst.SetUp;  
  begin  
      BeTestForm   :=   TBeTestForm.Create(nil);  
  end;  
   
  procedure   TTestCaseFirst.TearDown;  
  begin  
      BeTestForm.Destroy;  
  end;  
   
  procedure   TTestCaseFirst.TestFirst;  
  begin  
      Check(BeTestForm.BeTestFunction(1,   3)   =   3,   'First   Test   fail');  
  end;  
   
  procedure   TTestCaseFirst.TestSecond;  
  begin  
      Check(BeTestForm.BeTestFunction(1,   3)   =   3,   'Second   Test   fail');  
  end;  
   
  {   TTestCaseSecond   }  
   
  procedure   TTestCaseSecond.TestThird;  
  begin  
      Check(BeTestForm.BeTestFunction(1,   3)   =   3,   'Third   Test   fail');  
  end;  
   
  initialization  
    TestFramework.RegisterTest(TTestCaseFirst.Suite);  
    TestFramework.RegisterTest(TTestCaseSecond.Suite);  
   
  end.  
   
  ----------------------------------------------------------------  
  根据相关文档做了个测试的,  
  Check(BeTestForm.BeTestFunction(1,   3)   =   3,   'Third   Test   fail');  
  通过这里测试  
  TBeTestForm.BeTestFunction(I,   J:   Integer)  
  过程是否正确。  
   
  但感觉没有什么意义,可能是我没有理解DUnit的使用意图,到底DUnit应该如何来测试单元??? 问题点数:20、回复次数:3Top

1 楼LocustWei(LocustWei)回复于 2005-08-03 18:55:04 得分 0

单元测试,测试的是程序逻辑,并不关心业务。即设置各种边界看看程序能否正确处理。Top

2 楼jbmaster()回复于 2005-08-04 09:44:30 得分 0

那我也可以通过自己的方式来测试:  
   
  if   BeTestForm.BeTestFunction(1,   3)   =   3   then  
      ...  
  else  
      ...;  
   
  那也挺方便的,为什么需要使用DUnit来测试单元呢??Top

3 楼LocustWei(LocustWei)回复于 2005-08-04 10:28:17 得分 0

DUnit   只是一个辅助工具可以让你少写点单元测试代码(大量测试),顺便计算程序运行时间等。如果这些你都要自己做当然也没有问题。Top

相关问题

  • DUnit单元测试工具哪里有下载,请指示,十万火急!
  • 有谁知道或能提供delphi的单元测试工具Dunit
  • 单元测试工具
  • 关于单元测试(NUnit.org)
  • 单元测试的疑惑
  • 讨论:什么是单元测试,单元测试用例、单元测试过程应该如何写?怎样才能做好单元测试?
  • Nnuit 单元测试初学者2问
  • 征求asp的单元测试?
  • 单元测试问题!!!!急急急
  • 在vs2003中如何做单元测试?

关键词

  • 测试
  • check
  • betestform
  • betestfunction
  • tbetestform
  • ttestcasefirst
  • dunit
  • ttestcasesecond
  • testframework
  • 来测试单元

得分解答快速导航

  • 帖主:jbmaster

相关链接

  • Delphi类图书
  • Delphi类源码下载
  • Delphi控件下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo