unit BeTestUnit;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;type
TBeTestForm = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
function BeTestFunction(I, J: Integer): Integer;
end;var
BeTestForm: TBeTestForm;implementation{$R *.dfm}{ TBeTestForm }function TBeTestForm.BeTestFunction(I, J: Integer): Integer;
begin
Result := I * J;
end;end.--------------------------------------------------------------------------unit TestUnit;interfaceuses
TestFrameWork, BeTestUnit, Dialogs;type
TTestCaseFirst = class(TTestCase)
private
BeTestForm: TBeTestForm;
protected
procedure SetUp; override;
procedure TearDown; override;
published
procedure TestFirst;
procedure TestSecond;
end; TTestCaseSecond = class(TTestCase)
published
procedure TestThird;
end;implementation{ TTestCaseFirst }procedure TTestCaseFirst.SetUp;
begin
BeTestForm := TBeTestForm.Create(nil);
end;procedure TTestCaseFirst.TearDown;
begin
BeTestForm.Destroy;
end;procedure TTestCaseFirst.TestFirst;
begin
Check(BeTestForm.BeTestFunction(1, 3) = 3, 'First Test fail');
end;procedure TTestCaseFirst.TestSecond;
begin
Check(BeTestForm.BeTestFunction(1, 3) = 3, 'Second Test fail');
end;{ TTestCaseSecond }procedure TTestCaseSecond.TestThird;
begin
Check(BeTestForm.BeTestFunction(1, 3) = 3, 'Third Test fail');
end;initialization
TestFramework.RegisterTest(TTestCaseFirst.Suite);
TestFramework.RegisterTest(TTestCaseSecond.Suite);end.----------------------------------------------------------------
根据相关文档做了个测试的,
Check(BeTestForm.BeTestFunction(1, 3) = 3, 'Third Test fail');
通过这里测试
TBeTestForm.BeTestFunction(I, J: Integer)
过程是否正确。但感觉没有什么意义,可能是我没有理解DUnit的使用意图,到底DUnit应该如何来测试单元???
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;type
TBeTestForm = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
function BeTestFunction(I, J: Integer): Integer;
end;var
BeTestForm: TBeTestForm;implementation{$R *.dfm}{ TBeTestForm }function TBeTestForm.BeTestFunction(I, J: Integer): Integer;
begin
Result := I * J;
end;end.--------------------------------------------------------------------------unit TestUnit;interfaceuses
TestFrameWork, BeTestUnit, Dialogs;type
TTestCaseFirst = class(TTestCase)
private
BeTestForm: TBeTestForm;
protected
procedure SetUp; override;
procedure TearDown; override;
published
procedure TestFirst;
procedure TestSecond;
end; TTestCaseSecond = class(TTestCase)
published
procedure TestThird;
end;implementation{ TTestCaseFirst }procedure TTestCaseFirst.SetUp;
begin
BeTestForm := TBeTestForm.Create(nil);
end;procedure TTestCaseFirst.TearDown;
begin
BeTestForm.Destroy;
end;procedure TTestCaseFirst.TestFirst;
begin
Check(BeTestForm.BeTestFunction(1, 3) = 3, 'First Test fail');
end;procedure TTestCaseFirst.TestSecond;
begin
Check(BeTestForm.BeTestFunction(1, 3) = 3, 'Second Test fail');
end;{ TTestCaseSecond }procedure TTestCaseSecond.TestThird;
begin
Check(BeTestForm.BeTestFunction(1, 3) = 3, 'Third Test fail');
end;initialization
TestFramework.RegisterTest(TTestCaseFirst.Suite);
TestFramework.RegisterTest(TTestCaseSecond.Suite);end.----------------------------------------------------------------
根据相关文档做了个测试的,
Check(BeTestForm.BeTestFunction(1, 3) = 3, 'Third Test fail');
通过这里测试
TBeTestForm.BeTestFunction(I, J: Integer)
过程是否正确。但感觉没有什么意义,可能是我没有理解DUnit的使用意图,到底DUnit应该如何来测试单元???
...
else
...;那也挺方便的,为什么需要使用DUnit来测试单元呢??