Unit1.pas
上传用户:yjb1804
上传日期:2021-01-30
资源大小:3105k
文件大小:1k
源码类别:

Email服务器

开发平台:

Delphi

  1. unit Unit1;
  2. interface
  3. uses
  4.   {$IFDEF TESTING}
  5.   TestFramework,
  6.   {$ENDIF}
  7.   Classes, SysUtils;
  8. type
  9.   TMyObject = class(TObject)
  10.   public
  11.     procedure DoSomething;
  12.   end;
  13.   {$IFDEF TESTING}
  14.   TTestMyObject = class(TTestCase)
  15.   private
  16.     FMyObject: TMyObject;
  17.   public
  18.     procedure Setup; override;
  19.     procedure TearDown; override;
  20.   published
  21.     procedure testMyObject;
  22.   end;
  23.   {$ENDIF}
  24. implementation
  25. { TMyObject }
  26. procedure TMyObject.DoSomething;
  27. begin
  28.   // do something
  29. end;
  30. {$IFDEF TESTING}
  31. function Suite: ITestSuite;
  32. begin
  33.   Result := TTestSuite.Create('Test MyObject');
  34.   Result.AddTest(TTestMyObject.Create('testMyObject'));
  35. end;
  36. { TTestMyObject }
  37. procedure TTestMyObject.Setup;
  38. begin
  39.   FMyObject := TMyObject.Create;
  40. end;
  41. procedure TTestMyObject.TearDown;
  42. begin
  43.   FMyObject.Free;
  44. end;
  45. procedure TTestMyObject.testMyObject;
  46. begin
  47.   try
  48.     FMyObject.DoSomething;
  49.   except
  50.     check(false);
  51.   end;
  52. end;
  53. {$ENDIF}
  54. initialization
  55.   {$IFDEF TESTING}
  56.     RegisterTest('', TTestMyObject.Suite);
  57.   {$ENDIF}
  58. end.