DUnit:如何运行测试? [英] DUnit: How to run tests?

查看:308
本文介绍了DUnit:如何运行测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何从IDE运行 TestCase

我创建了一个新的项目,单一简单的形式:

i created a new project, with a single, simple, form:

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 应该做什么:

Now i'll add a test case to check that pushing Button1 does what it should:

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 ,则表单只会出现:

Given what i've done (test code in the GUI project), how do i now trigger a run of the tests? If i push F9 then the form simply appears:

alt text http://i39.tinypic.com/zsobhv.jpg

理想情况下,IDE中会有一个按钮或菜单选项说运行DUnit测试

Ideally there would be a button, or menu option, in the IDE saying Run DUnit Tests:

alt text http ://i44.tinypic.com/24wvipw.jpg

我住在梦幻世界吗?一个幻想的土地,住在棒棒糖车道上的一个口袋里?

Am i living in a dream-world? A fantasy land, living in a gumdrop house on lollipop lane?

推荐答案

我同意Uwe Raabe,但有时它可以是有用的在您的应用程序中有一个隐藏链接来运行DUnit GUI。我使用:

I agree with Uwe Raabe, but sometimes it can be useful to have a 'hidden' link within your app to run the DUnit GUI. I use:

TGUITestRunner.runRegisteredTests;

从DUnit GUI中的按钮调用它将打开,以便您手动运行并查看测试输出。

Call this from your button at the DUnit GUI will open for you to manually run and view test output.

例如,如果在打开软件自己的控制面板,你会得到一些高级条目:

For example, if you hold down a special key combination when opening the software's own "Control Panel", you get some advanced entries:

>

这篇关于DUnit:如何运行测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆