вторник, 17 марта 2015 г.

Testing of calculator №2. Adding of business-logic test using visual controls

Original in Russian: http://programmingmindstream.blogspot.com/2014/02/2.html

Table of contents

All the sources are available here 

 Let’s add ONE test of “business logic” as it is:

The abstract part:

unit CalculatorGUITest;
 
interface
 
uses
  TestFrameWork,
  MainForm
  ;
 
type
  TCalculatorGUITest = class(TTestCase)
   protected
    procedure VisitForm(aForm: TfmMain); virtual; abstract;
   published
    procedure DoIt;
  end;//TCalculatorGUITest
 
implementation
 
uses
  Forms
  ;
 
procedure TCalculatorGUITest.DoIt;
var
 l_Index : Integer;
begin
 for l_Index := 0 to Screen.FormCount do
  if (Screen.Forms[l_Index] Is TfmMain) then
  begin
   VisitForm(Screen.Forms[l_Index] As TfmMain);
   break;
  end;//Screen.Forms[l_Index] Is TfmMain
end;
 
end.

The specific test:

unit PlusTest;
 
interface
 
uses
  CalculatorGUITest,
  MainForm
  ;
 
type
  TPlusTest = class(TCalculatorGUITest)
   protected
    procedure VisitForm(aForm: TfmMain); override;
  end;//TPlusTest
 
implementation
 
uses
  TestFrameWork,
  SysUtils
  ;
 
procedure TPlusTest.VisitForm(aForm: TfmMain);
const
 aA = 10;
 aB = 20;
begin
 aForm.Edit1.Text := IntToStr(aA);
 aForm.Edit2.Text := IntToStr(aB);
 aForm.Button1.Click;
 Check(StrToInt(aForm.Edit3.Text) = aA + aB);
end;
 
initialization
 TestFramework.RegisterTest(TPlusTest.Suite);
 
end.

As for me, it is all clear here.

We find the main form of the application. We type text to Edit1 and Edit2. We press the “addition” button. We check the result from Edit3.

Repository


Комментариев нет:

Отправить комментарий