These rules ensure proper project organization, test implementation, and workspace structure in AL-Go based development environments.
Establish clear separation between application code and test code in AL-Go workspace environments.
// Good example - Proper AL-Go workspace structure
Repository/
├── .AL-Go/
├── .github/
├── App/
│ ├── src/
│ │ ├── Setup/
│ │ ├── Feature1/
│ │ ├── Feature2/
│ │ ├── APIs/
│ ├── app.json
│ └── launch.json
├── Test/
│ ├── src/
│ │ ├── SetupTests/
│ │ ├── Feature1Tests/
│ │ ├── Feature2Tests/
│ │ ├── IntegrationTests/
│ ├── app.json
│ └── launch.json
└── al.code-workspace
Control when and how test code is generated to maintain focus on main application implementation.
Establish correct dependency relationships between App and Test projects.
// Good example - Test project app.json
{
"dependencies": [
{
"id": "your-app-id",
"name": "Your App Name",
"publisher": "Your Publisher",
"version": "1.0.0.0"
},
{
"id": "dd0be2ea-f733-4d65-bb34-a28f4624fb14",
"name": "Library Assert",
"publisher": "Microsoft",
"version": "20.0.0.0"
}
]
}
Write comprehensive unit tests that ensure reliability of business logic.
// Good example - Well-structured unit test with standard library codeunits
codeunit 50200 "Customer Management Tests"
{
Subtype = Test;
var
Assert: Codeunit Assert;
LibrarySales: Codeunit "Library - Sales";
LibraryInventory: Codeunit "Library - Inventory";
LibraryRandom: Codeunit "Library - Random";
LibraryERM: Codeunit "Library - ERM";
[Test]
procedure GivenValidCustomer_WhenCreatingCustomer_ThenCustomerIsCreated()
var
Customer: Record Customer;
CustomerManagement: Codeunit "Customer Management";
CustomerNo: Code[20];
begin
// Given - Valid customer data using library
LibrarySales.CreateCustomer(Customer);
Customer."Credit Limit (LCY)" := LibraryRandom.RandDec(10000, 2);
// When - Creating customer
CustomerNo := CustomerManagement.CreateCustomer(Customer);
// Then - Customer is created successfully
Assert.IsTrue(Customer.Get(CustomerNo), 'Customer should be created');
Assert.AreEqual(Customer.Name, Customer.Name, 'Customer name should match');
end;
[Test]
procedure GivenSalesOrder_WhenPostingOrder_ThenInvoiceIsCreated()
var
SalesHeader: Record "Sales Header";
SalesLine: Record "Sales Line";
Item: Record Item;
PostedInvoiceNo: Code[20];
begin
// Given - Sales order with library-created data
LibraryInventory.CreateItem(Item);
LibrarySales.CreateSalesHeader(SalesHeader, SalesHeader."Document Type"::Order, '');
LibrarySales.CreateSalesLine(SalesLine, SalesHeader, SalesLine.Type::Item, Item."No.", LibraryRandom.RandInt(10));
// When - Posting sales order
PostedInvoiceNo := LibrarySales.PostSalesDocument(SalesHeader, true, true);
// Then - Posted invoice exists
Assert.AreNotEqual('', PostedInvoiceNo, 'Posted invoice should be created');
end;
}
Organize test files to mirror the application structure while maintaining clear separation.
// Good example - Mirrored test structure
App/src/
├── NoSeries/
│ ├── NoSeries.Table.al
│ └── NoSeries.Page.al
└── Sales/
└── Invoice/
└── SalesInvoice.Page.al
Test/src/
├── NoSeries/
│ └── NoSeriesTests.Codeunit.al
├── Sales/
│ └── Invoice/
│ └── SalesInvoiceTests.Codeunit.al
└── Common/
└── TestHelpers/
└── TestDataFactory.Codeunit.al
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.