testdemoclasses.pas

来自「source code for Marco Cantu s book Delph」· PAS 代码 · 共 81 行

PAS
81
字号
unit TestDemoClasses;
{

  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, DemoClasses;

type
  // Test methods for class TMyTest
  TestTMyTest = class(TTestCase)
  strict private
    FMyTest: TMyTest;
  public
    procedure SetUp; override;
    procedure TearDown; override;
    procedure AddNegativeValue;
  published
    procedure TestText;
    procedure TestAdd;
    procedure TestAddException;
  end;

implementation

uses
  Classes, SysUtils;

procedure TestTMyTest.SetUp;
begin
  FMyTest := TMyTest.Create;
end;

procedure TestTMyTest.TearDown;
begin
  FMyTest.Free;
  FMyTest := nil;
end;

procedure TestTMyTest.TestText;
var
  ReturnValue: string;
begin
  fMyTest.Number := 10;
  ReturnValue := FMyTest.Text;
  // this test fails on purpose
  CheckEquals (ReturnValue, '10', 'Error extracting text [fails on purpose]');
end;

procedure TestTMyTest.TestAdd;
begin
  FMyTest.Number := 10;
  FMyTest.Add(5);
  CheckEquals(15, FMyTest.NUmber);
end;

procedure TestTMyTest.TestAddException;
begin
  FMyTest.Number := 10;
  CheckException (AddNegativeValue, Exception);
end;

procedure TestTMyTest.AddNegativeValue;
begin
  FMyTest.Add(-5);
end;

initialization
  // Register any test cases with the test runner
  RegisterTest(TestTMyTest.Suite);
end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?