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;
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs //************* Start Copy ***************** ,TestMe,TestMe_Types ,TestCodeType, TestCodeLevelUnits //************* End Copy ******************* ;
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
//************* 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.
type TTestMethod = (tmDiv);
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;
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)
-