Friday, June 25, 2010

Dynamics NAV Testing Framework - Create Handler Functions

Microsoft Dynamics NAV 2009 SP1 includes the following features to help you test your application:

  • Test codeunits

  • Test runner codeunits

  • UI handlers

  • ASSERTERROR statement

Application Test Toolset provided by Microsoft includes the Test Runner and sample Test Codeunits.

To create automated tests, you must write code to handle all UI interactions so that the tests do not require user interaction when running. To do this, you create the following special handler functions:

  • MessageHandler: Handles MESSAGE statements.
  • ConfirmHandler: Handles CONFIRM statements.
  • StrMenuHandler: Handles STRMENU statements.
  • FormHandler: Handles specific forms or pages that are not run modally.
  • ModalFormHandler: Handles specific forms or pages that are run modally.
  • ReportHandler: Handles specific reports.

In the following post, I included sample UI Handler Functions which can be used while creating test codeunits.

Signature: MessageHandler <Function name>(<Msg> : Text[1024])

Sample Code:

    [MessageHandler]
    PROCEDURE MessageHandler@1100499002(Msg@1100499000 : Text[150]);
    VAR
      Text001@1100499001 : TextConst 'ENU=Sales Order posted sucessfully.';
    BEGIN
      IF Msg <> Text001 THEN
        ERROR('Unknown Message');
    END;

 

Signature: ConfirmHandler <Function name>(<Question> : Text[1024]; VAR <Reply> : Boolean)

Sample Code:

    [ConfirmHandler]
    PROCEDURE ConfirmDialogYes@1102601013(Question@1102601000 : Text[1024];VAR Reply@1102601001 : Boolean);
    VAR
      Text001@1100499001 : TextConst 'ENU=Do you want to post the Sales Order?';
    BEGIN
      IF Question <> Text001 THEN
        ERROR('Unknown Confirm Text; %1',Question);
      Reply := TRUE;
    END;

 

Signature: StrMenuHandler <Function name>(<Options : Test[1024]; VAR <Choice> : Integer; <Instruction> : Text[1024])

Sample Code:

    [StrMenuHandler]
    PROCEDURE StrMenuHandler@1100499000(Options@1100499000 : Text[100];VAR Choice@1100499001 : Integer;Instruction@1100499002 : Text[100]);
    VAR
      Text000@1100499003 : TextConst 'ENU=&Ship,&Invoice,Ship &and Invoice';
    BEGIN
      IF Options = Text000 THEN
        Choice := 1;
    END;

 

Signature: FormHandler <Function name>(VAR <form name> : Form <form id>)

Sample Code:

    [FormHandler]
    PROCEDURE FormHandler@1100499001(VAR FormName@1100499000 : Form 21);
    BEGIN
      FormName.ActivateFields
    END;

 

Signature: ModalFormHandler <Function name>(VAR <form name> : Form <form id>; VAR <Response> : Action)

Sample Code:

    [ModalFormHandler]
    PROCEDURE ModalFormHandler@1100499002(VAR FormName@1100499000 : Form 342;VAR ReplyAction@1100499001 : Action);
    BEGIN
      ReplyAction := ACTION::LookupOK;
    END;

NOTE: UI Handler functions should be specified in the main test function as below.

image

1 comment: