以下是實現的代碼:
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)=4,’Second Test fail’);
end;
//Register TestCase
initialization
TestFramework.RegisterTest(TTestCaseFirst.Suite);
end.
Check是TestCase類提供的一個方法。以下是TestCase的實現代碼:
procedure TTestCase.Check(condition :boolean; msg :string);
begin
if (not condition) then
Fail(msg, CallerAddr);
End;
如果Check沒有通過的話,Dunit將報錯。錯誤提示就在第二個參數中定義,其他有關類及方法的定義請看連機文檔,文檔放在
Dunit安裝目錄\doc\API\IDH_Library_DUnit_-_Xtreme_Unit_Testing_for_Delphi.htm
延伸閱讀
文章來源于領測軟件測試網 http://www.kjueaiud.com/