Automated Tests in Dynamics 365 Business Central: Run AL Tests from Visual Studio Code

March 30, 2026
4 min read
By Maksymilian Meller

Table of Contents

This is a list of all the sections in this post. Click on any of them to jump to that section.

Run AL Tests from Visual Studio Code

Microsoft Dynamics 365 Business Central now allows developer to run automated tests direclty from Visual Studio Code. This feature was introduced in the 2026 release wave 1 (BC28). It significantly improves the developer workflow.

Why This Matters

Until now, running automated tests required switching context e.g. using web client or waiting for the CI/CD pipelines. This slowed down developers workflows.

With built-in test excecution in Visual Studio Code, developers can:

  • Run tests without leaving the development environment
  • Get fast feedback on code changes
  • Debug failing tests faster
  • More easly implement test-driven-development (TDD)

Prerequisites

If you are reading this while version 28 is still in preview, make sure that the AL Language Extension is set to pre-release version.

Official documentation:

prerelease

You will notice a new Testing icon in Visual Studio Code.

In this section, you can find all automated test available in the current workspace. They are grouped by applicaton and test codeunits.

testing

Running test in AL

For each codeunit or individual test, there are three available methods:

Run Test

This option runs selected codeunits and/or tests

run_test

You can also run test directly from the AL file context.

run_from_code

Debug Test

This option allows you to debug the selected test.

Debug

Run Test with Coverage

It creates coverage.json file used for testing code coverage.

Tested functions

Tested functions include an additional indicator showing the latest result. You can also run tests directly from the function level, which is a very convenient feature.

function

Results

Test results are displayed in multiple places:

  • Test Results section after you click on the test
  • Testing panel on the left side
  • For each codeunit and test directly in the AL file.

results

Fix Test using AI

You can try the Fix Test Failure feature, where AI suggests changes to help test pass.

AI

Code

// Welcome to your new AL extension.
// Remember that object names and IDs should be unique across all extensions.
// AL snippets start with t*, like tpageext - give them a try and happy coding!
codeunit 50100 Test
{
Subtype = Test;
[Test]
// Scenario: Create a sales order and verify that the bill-to customer is the same as the sell-to customer by default.
procedure CreateSalesOrder()
var
Customer: Record Customer;
Customer2: Record Customer;
SalesHeader: Record "Sales Header";
LibrarySales: Codeunit "Library - Sales";
SalesAdditionalFunctions: Codeunit "Sales Additional Functions";
Assert: Codeunit Assert;
begin
// given
LibrarySales.CreateCustomer(Customer);
LibrarySales.CreateCustomer(Customer2);
LibrarySales.CreateSalesHeader(SalesHeader, "Sales Document Type"::Order, Customer."No.");
// when
SalesAdditionalFunctions.ChangeBillTo(SalesHeader, Customer2."No.");
// then
Assert.AreEqual(SalesHeader."Sell-to Customer No.", SalesHeader."Bill-to Customer No.", 'Bill-to is different than Sell-to');
end;
[Test]
// Scenario: Create a sales invoice and verify that the bill-to customer is the same as the sell-to customer by default.
procedure CreateSalesInvoice()
var
Customer: Record Customer;
Customer2: Record Customer;
SalesHeader: Record "Sales Header";
LibrarySales: Codeunit "Library - Sales";
SalesAdditionalFunctions: Codeunit "Sales Additional Functions";
Assert: Codeunit Assert;
begin
// given
LibrarySales.CreateCustomer(Customer);
LibrarySales.CreateCustomer(Customer2);
LibrarySales.CreateSalesHeader(SalesHeader, "Sales Document Type"::Invoice, Customer."No.");
// when
SalesAdditionalFunctions.ChangeBillTo(SalesHeader, Customer."No.");
// then
Assert.AreEqual(SalesHeader."Sell-to Customer No.", SalesHeader."Bill-to Customer No.", 'Bill-to is different than Sell-to');
end;
}
codeunit 50101 "Sales Additional Functions"
{
procedure ChangeBillTo(var SalesHeader: Record "Sales Header"; BillToCustomerNo: Code[20])
begin
SalesHeader.Validate("Bill-to Customer No.", BillToCustomerNo);
SalesHeader.Modify();
end;
}

Conclusion

Running automated tests directly in Visual Studio Code is a major improvement for developers. It increase productivity and shortens feedback loop. It easier to adpot test-driven-development (TDD).

It has real impact on code quality and delivery speed.