IDE에서 TestCase을 어떻게 실행합니까? DUnit : 테스트를 실행하는 방법?
은 내가 하나, 간단한, 양식, 새로운 프로젝트를 생성 :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
가 이상적으로 실행은 DUnit을 말하는 IDE에서, 버튼 또는 메뉴 옵션이있을 것입니다 것은 시험 :alt text http://i44.tinypic.com/24wvipw.jpg
나는 꿈의 세계에 살고 있습니까? 롤리팝 차선의 껌 집에 살고있는 환상의 땅?
UI 이벤트 핸들러를 직접 테스트하지 않고 비즈니스 로직을 클래스로 분리하면 비즈니스 로직을 단위 테스트로 쉽게 찾을 수 있습니다 . –
@Monk : 단점은 코드가 여러 클래스에 걸쳐 있거나 여러 파일이 악화되어 있다는 것입니다. –