Table of Contents

Quick start (4 steps)

Just 4 steps for professional testing

To test the Divide method you need 4 steps
An example of a function that will be tested:

    Tfrm_Calc = class (TForm )
    public
     Function Divide(iA,iB:integer):integer;
 
...
Function Tfrm_Calc.Divide(iA,iB:integer):integer;
begin
 result:=iA div iB;
end;    

1. Copy-Paste 3 pieces (unit, methods, initialization)

1.1. Uses plug in modules TestMe

uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs
   //************* Start Copy *****************
        ,TestMe,TestMe_Types
        ,TestCodeType, TestCodeLevelUnits
   //************* End Copy *******************
    ;

1.2. Define 2 methods for class registration and testing _RegisterMethod and_TestMethods

type
    Tfrm_Calc = class (TForm )
         private
   //************* Start Copy *****************
           class var F_pIndexClass:TPIndexValue;
           class Procedure _RegisterMethod;
           class Function _TestMethods( IMethod:IRunMethodParam):TTestResultParam;
   //************* End Copy *******************
         {$ENDIF}
    public

1.3. Register the module that will be tested in the block initialization

   //************* Start Copy *****************
initialization
  if GetTestMe.bIsTestCode then begin
     with GetTestMe.ITestCode do begin
        TForm1.F_pIndexClass := IRegisterClass(TForm1._RegisterMethod,TForm1._TestMethods,'TForm1','Test many reg methods');
     end;
  end;
   //************* End Copy *******************
end.

2. Describe the methods that will be tested

  type
   TTestMethod = (tmDiv);

3. enter the parameters

class procedure TCalc._RegisterMethod;
begin
 if not GetTestMe.bIsTestCode then  Exit;
 with GetTestMe.ITestCode do begin
  if not ISetDefaultIndClassUnitApp(F_pIndexClass) then exit; // Set position
 
   IRegisterMethod(tmDiv  ,'tmDiv'  ,'Test Div operation');// Test methods
    IRegisterMethodParams([15,5],[3],'15 div 5=3'); // True result
    IRegisterMethodParams([2,2],[1],'2 div 2=1');   // True result
 end; //withend;
end;

4. let's write a call of the tested methods.

class function TCalc._TestMethods(
  IMethod: IRunMethodParam): TTestResultParam;
begin
 case TTestMethod(IMethod.IGetNumParamUser)  of
    tmDiv: begin
             if (Form1.divide(IMethod.IGetArrParam(0).AsInteger,IMethod.IGetArrParam(1).AsInteger)
               =
                IMethod.IGetArrResultForTestMethod(0).AsInteger) then
              result:=trOk
             else
              result:=trError;
           end;
  end; // case
end;

Final application test (video)

-

Download and try

Download Now