📄 testdemoclasses.pas
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -