AL icon indicating copy to clipboard operation
AL copied to clipboard

Handlers in test codeunit

Open f4n0 opened this issue 7 years ago • 6 comments

Describe the bug Hi all, I have to test an app (using test codeunit) but I'm in a sort of loop. Here's why. I have to process a record (using an action) and it reacts in 2 different ways:

  1. If the record was just created, you execute the action and this works normally
  2. if the record was already processed it will prompt a confirm message

Now, In the first case the "ConfirmHandler" it will not be executed but in the second case, it will be executed. If I omit the handler in one case it will throw an error, if I set this it will throw an error in another case.

What can I do? It will not be a chance to set the error "The handler was to executed" to a warning? Thanks

Versions:

  • AL Language: 3.0.118998
  • Business Central: Spring Release (RTM 14.0.29530.0)

f4n0 avatar May 07 '19 12:05 f4n0

This repository no longer handles general questions and is only dedicated to bug reports and feature suggestions for the latest preview version of the AL compiler and developer tools.

To get help for your question please use one of the following resources: Business Central Community mibuso forum Dynamics User Group

PooyaKharamesh avatar May 07 '19 14:05 PooyaKharamesh

I think you should have test function with a CnfmHandlr to handle the Confirm Msg with an "if condition" and define the handler function in the test function.

ashikkrux avatar May 15 '19 04:05 ashikkrux

Hi @ashikkrux I don't get the point (or vice versa). If I will do what you suggest it will return in one case handler not executed and in the other works perfectly Can you explain better? Thanks

f4n0 avatar May 15 '19 07:05 f4n0

Can you share some screenshots or a small repo?

You are covering the two cases with the same TestFunction or separate TestFunctions?

If you wanna take it offline, you can email me [email protected]

ashikkrux avatar May 15 '19 07:05 ashikkrux

I have a list. For each line, you can execute an action. If you do that it finds related lines and if they were found it will ask the user "are you sure? existing line will be deleted" otherwise it will execute the action without user input. So, in any case, I will have to redesign the code, not the test codeunit. I've been thinking for the past 2 weeks (asking also to my colleagues) about what it can be done without touching the real code. This is why I've asked about throwing warnings and not errors in test codeunit if a handler was not being executed.

f4n0 avatar May 15 '19 12:05 f4n0

Now I get it clearly.

I think you have to redesign the code. Here is a easy way of doing it

IF NOT GUIALLOWED THEN Confirmed := TRUE ELSE Confirmed := CONFIRM(DeferralLineQst,FALSE); IF Confirmed THEN UpdateLines();

Hope this helps.

ashikkrux avatar May 16 '19 03:05 ashikkrux