I am using Delphi XE7 and want to test my program with the unit test provided by DUnit. My code is:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
with Form1 do
Edit3.Text := IntToStr(StrToInt(Edit1.Text) + StrToInt(Edit2.Text));
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
Form1.Edit1.Text := '5';
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.Edit2.Text := '4';
end;
end.
So i created a unit test with some test cases for the code:
unit TestUnit1;
interface
uses
TestFramework, System.SysUtils, Vcl.Graphics, Vcl.StdCtrls, Winapi.Windows,
System.Variants, System.Classes, Vcl.Dialogs, Vcl.Controls, Vcl.Forms,
Winapi.Messages, Unit1;
type
TestTForm1 = class(TTestCase)
strict private
FForm1: TForm1;
public
procedure SetUp; override;
procedure TearDown; override;
published
procedure TestButton1Click;
procedure TestFormActivate;
procedure TestFormCreate;
end;
implementation
procedure TestTForm1.SetUp;
begin
FForm1 := TForm1.Create;
end;
procedure TestTForm1.TearDown;
begin
FForm1.Free;
FForm1 := nil;
end;
procedure TestTForm1.TestButton1Click;
var
Sender: TObject;
begin
FForm1.Button1Click(Sender);
CheckEquals(StrToInt(Form1.Edit1.Text)+StrToInt(Form1.Edit2.Text),StrToInt(Form1.Edit3.Text));
end;
procedure TestTForm1.TestFormActivate;
var
Sender: TObject;
begin
FForm1.FormActivate(Sender);
CheckEquals(5, StrToInt(Form1.Edit1.Text));
end;
procedure TestTForm1.TestFormCreate;
var
Sender: TObject;
begin
FForm1.FormCreate(Sender);
CheckEquals(4, StrToInt(Form1.Edit2.Text));
end;
initialization
RegisterTest(TestTForm1.Suite);
end.
My problem now is that when I want to start the unit test I get an error e2035 Not enough actual parameters at "FForm1 := TForm1.Create;" What I already know is that the error means that parameters are missing, but I have no idea what parameters i can add so that the code will work. Anyone know any help?
Aucun commentaire:
Enregistrer un commentaire