microsoft / microsoft/AL

[Bug] Running Tests from VS Code differs from running in AL Test Tool. GuiAllowed() is false from VS Code and true from AL Test Tool

Open
#8,217 1 comment 7 reactions 1 assignee View on GitHub

@thloke is already working on this.

Since Apr 14, 2026.

accepted
Dominant language
PowerShell
Stars
881
Forks
285
Avg merge
3d 36m
Merged PRs (30d)
1

Description

1. Describe the bug
IΓÇÖve been looking into running Business Central tests directly from VS Code. Until now, IΓÇÖve been using the AL Test Tool to run the tests. All my tests have run successfully there. The tests also run successfully in GitHub Pipelines and Azure DevOps Pipelines. However, when I run the same test on the same database in the same tenant from VS Code, the test fails. One possible cause seems to be the different handling of GuiAllowed(). In the AL Test Tool, GuiAllowed = true is returned (and apparently also when running tests in pipelines). When running tests from VS Code, GuiAllowed = false was returned.
Consequently, the ConfirmHandlers in the tests that relied on this were no longer executed, causing the tests to fail.

I think the runtime environment should return the same values for system functions (and in particular GuiAllowed) regardless of where a test is called from. I expect the value to be the same as it is returned in the AL Test Tool to ensure backward compatibility.

2. To Reproduce

  1. Create an app that includes a confirmation prompt in a process. For example, something like this:

    Image
  2. Create a test in a test codeunit that uses this function. The test function should have a ConfirmHandler. For example, like this:

    Image
  3. Run the test once from the AL Test Tool in the client -> The test should succeed

    Image
  4. Run the test from VS Code. The test fails because the ConfirmHandler was not executed.

    Image

Code to copy into a TestCodeunit:

    procedure ShowConfirm(ConfirmQst: Text): Boolean
    begin
        if GuiAllowed() then begin
            Commit();
            exit(Confirm(ConfirmQst));
        end;

        exit(true);
    end;

    [Test]
    [HandlerFunctions('GuiallowedFlagConfirmHandler')]
    procedure TestGuiallowedFlag()
    begin
        ShowConfirm('Test Confirm');
    end;

    [ConfirmHandler]
    procedure GuiallowedFlagConfirmHandler(Question: Text[1024]; var Reply: Boolean)
    begin
        Reply := true;
    end;

Note: Because the developers need to copy and paste the code snippet, including a code snippet as a media file (i.e. .gif) is not sufficient.

3. Expected behavior
I think the runtime environment should return the same values for system functions (and in particular GuiAllowed) regardless of where a test is called from. I expect the value to be the same as it is returned in the AL Test Tool to ensure backward compatibility.

4. Actual behavior
See the description above

5. Versions:

  • AL Language: 18.0.2190758
  • Visual Studio Code:
Image
  • Business Central: W1 29.0 (Platform 29.0.47575.0 + Application 29.0.47628.0)
  • List of Visual Studio Code extensions that you have installed: AL Language
  • Operating System:
    • Windows
    • Linux
    • MacOS
Final Checklist

Please remember to do the following:

  • Search the issue repository to ensure you are reporting a new issue

  • Reproduce the issue after disabling all extensions except the AL Language extension

  • Simplify your code around the issue to better isolate the problem

Internal work item: AB#630907

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.