Handlers in test codeunit
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:
- If the record was just created, you execute the action and this works normally
- 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)
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
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.
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
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]
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.
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.