一:新建所需测试单元
unit UFunction; interface type TMyfun = class (TObject) public function GetMyAge(Birthday:TDateTime):Integer; end ; implementation uses SysUtils,DateUtils; { TMyfun } function TMyfun.GetMyAge(Birthday: TDateTime): Integer; var syear,smonth,sday:Word;byear,bmoth,bday:Word; begin syear: = YearOf(Now); // DecodeDate(Now,syear,smonth,sday);DecodeDate(Birthday,byear,bmoth,bday);Result: = syear - byear; end ; end .二:新建测试模块DUint->Test Module
unit UFunctionTests; interface uses UFunction,TestFrameWork; type TMyfunTests = class (TTestCase) private Myfun:TMyfun; // 声明测试单元 protected procedure SetUp; override ; procedure TearDown; override ; published // Test methods procedure TestGetMyAge; end ; implementation uses DateUtils,SysUtils; { TMyfunTests } procedure TMyfunTests.SetUp; begin inherited ;Myfun: = TMyfun.Create; end ; procedure TMyfunTests.TearDown; begin inherited ;Myfun.Destroy; end ; procedure TMyfunTests.TestGetMyAge; var dt:TDateTime; begin dt: = Now;dt: = incyear(dt, - 10 );Self.CheckEquals( 11 ,Myfun.GetMyAge(dt), ' yyyy ' ); end ; initialization TestFramework.RegisterTest( ' UFunctionTests Suite ' ,TMyfunTests.Suite); end .三:新建测试项目 DUint->Test Project
// Uncomment the following directive to create a console application // or leave commented to create a GUI application... // { $APPTYPE CONSOLE } program Tests; uses TestFramework { $IFDEF LINUX } ,QForms,QGUITestRunner { $ELSE } ,Forms,GUITestRunner { $ENDIF } ,TextTestRunner,UFunctionTests in ' UFunctionTests.pas ' ,UFunction in ' ..\UFunction.pas ' ; { $R *.RES } begin Application.Initialize; { $IFDEF LINUX } QGUITestRunner.RunRegisteredTests; { $ELSE } if System.IsConsole then TextTestRunner.RunRegisteredTests else GUITestRunner.RunRegisteredTests; { $ENDIF } end . posted on 2011-07-11 16:20 龙七 阅读( ...) 评论( ...) 编辑 收藏转载于:https://www.cnblogs.com/Dragon7/archive/2011/07/11/2103166.html