Guest User

Untitled

a guest
Jun 24th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. program UnitTest1;
  2.  
  3. {$IFDEF CONSOLE_TESTRUNNER}
  4. {$APPTYPE CONSOLE}
  5. {$ENDIF}
  6.  
  7. uses
  8. Forms, Classes, SysUtils,
  9. TestFramework,
  10. GUITestRunner,
  11. TextTestRunner;
  12.  
  13. {$R *.RES}
  14.  
  15. type
  16. TIntTestCase = class(TTestCase)
  17. private
  18. FValue: Integer;
  19. public
  20. constructor Create(AValue: Integer); reintroduce;
  21. function GetName: string; override;
  22. published
  23. procedure Run;
  24. end;
  25.  
  26. { TIntTestCase }
  27.  
  28. constructor TIntTestCase.Create(AValue: Integer);
  29. begin
  30. inherited Create('Run');
  31. FValue := AValue;
  32. end;
  33.  
  34. function TIntTestCase.GetName: string;
  35. begin
  36. Result := Format('Run_%.3d', [FValue]);
  37. end;
  38.  
  39. procedure TIntTestCase.Run;
  40. begin
  41. Check(FValue mod 2 = 0, Format('%d is not an even value', [FValue]));
  42. end;
  43.  
  44. procedure RegisterTests;
  45. const
  46. TestCount = 10;
  47. ValueHigh = 1000;
  48. var
  49. I: Integer;
  50. begin
  51. Randomize;
  52. for I := 0 to TestCount - 1 do
  53. RegisterTest(TIntTestCase.Create(Random(ValueHigh) + 1));
  54. end;
  55.  
  56. begin
  57. Application.Initialize;
  58. RegisterTests;
  59. if IsConsole then
  60. TextTestRunner.RunRegisteredTests
  61. else
  62. GUITestRunner.RunRegisteredTests;
  63. end.
Add Comment
Please, Sign In to add comment