Ian*_*oyd 10 delphi tdd unit-testing dunit delphi-5
我如何从IDE 运行TestCase?
我用一个简单的形式创建了一个新项目:
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;
type
  TForm1 = class(TForm)
  private
  public
  end;
var
  Form1: TForm1;
implementation
{$R *.DFM}
end.
现在我将添加一个测试用例来检查推送Button1是否应该完成:
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;
type
  TForm1 = class(TForm)
     Button1: TButton;
     procedure Button1Click(Sender: TObject);
  private
  public
  end;
var
  Form1: TForm1;
implementation
{$R *.DFM}
uses
    TestFramework;
type
  TForm1Tests = class(TTestCase)
  private
        f: TForm1;
  protected
     procedure SetUp; override;
     procedure TearDown; override;
  published
     procedure TestButton1Click;
  end;
procedure TForm1.Button1Click(Sender: TObject);
begin
    //todo
end;
{ TForm1Tests }
procedure TForm1Tests.SetUp;
begin
  inherited;
    f := TForm1.Create(nil);
end;
procedure TForm1Tests.TearDown;
begin
    f.Free;
  inherited;
end;
procedure TForm1Tests.TestButton1Click;
begin
    f.Button1Click(nil);
    Self.CheckEqualsString('Hello, world!', f.Caption);
end;
end.
鉴于我已经完成了(GUI项目中的测试代码),我现在如何触发测试运行?如果我推,F9那么表单就会出现:
alt text http://i39.tinypic.com/zsobhv.jpg
理想情况下,IDE中会有一个按钮或菜单选项,说"运行DUnit测试:
替代文字http://i44.tinypic.com/24wvipw.jpg
我生活在梦想世界吗?一个梦幻般的土地,住在棒棒糖车道的胶糖屋里?
Uwe*_*abe 12
将TestCase添加到主项目是不可取的.您应该创建一个单独的TestProject(您可以将它与主项目放在同一个ProjectGroup中),添加一个TestCase并运行.
我同意Uwe Raabe的观点,但有时在您的应用程序中使用"隐藏"链接来运行DUnit GUI会很有用.我用:
TGUITestRunner.runRegisteredTests;
通过DUnit GUI上的按钮调用此选项将打开,您可以手动运行并查看测试输出.
例如,如果在打开软件自己的"控制面板"时按住特殊组合键,则会获得一些高级条目:

| 归档时间: | 
 | 
| 查看次数: | 2477 次 | 
| 最近记录: |