al-test-generation
Skill61 starsChanged 20 days agoMITView on GitHub
Guide for creating AL tests for Microsoft Dynamics 365 Business Central. Use this when asked to write, create, or generate AL test codeunits, test procedures, or test automation for Business Central.
In this repository10 other files it gives its agents.
- src/bcbench/agent/shared/instructions/microsoft-BCApps/AGENTS.mdAGENTS.md
- src/bcbench/agent/shared/instructions/microsoftInternal-NAV/AGENTS.mdAGENTS.md
- .github/copilot-instructions.mdCopilot instructions
- create-releaseSkill
- update-agent-harnessSkill
- bc-al-query-mcpSkill
- al-test-generationSkill
- bc-ext-advisorSkill
- extensibility-request-implementSkill
- bcbench-exampleSkill
The file
We split this skill into the rules it gives an agent
12 rules. About 0 are common, 10 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 10
Before writing any test code:
- Distinctive: line 11
Read and understand the procedure or functionality being tested
- Distinctive: line 19
Look for these patterns in the code under test:
- Distinctive: line 37
Before inserting test data:
- Distinctive: line 38
Read the table definition for all fields receiving values
- Distinctive: line 40
Ensure related records exist before inserting test data
- Very specific: line 41
Use Library functions (e.g., LibrarySales, LibraryPurchase) to create prerequisite data
- Distinctive: line 45
Follow the AAA pattern (Arrange-Act-Assert):
- Distinctive: line 88
Use descriptive test procedure names that explain what is being tested
- Distinctive: line 90
Use Library Variable Storage to pass data between handlers and tests
- Distinctive: line 91
Do NOT verify values inside handler procedures
- Very specific: line 93
Use Initialize() procedure to set up common test fixtures
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
To create AL tests for Microsoft Dynamics 365 Business Central, follow this process:
1. Analyze the Code Under Test
Before writing any test code:
- Read and understand the procedure or functionality being tested
- Trace through all code paths to identify UI interactions
- Examine table definitions for TableRelation constraints
2. Identify Required Handler Methods
CRITICAL: Tests fail with "Unhandled UI" errors when handlers are missing.
Look for these patterns in the code under test:
| Code Pattern | Required Handler |
Confirm() | [ConfirmHandler] |
Message() | [MessageHandler] |
StrMenu() | [StrMenuHandler] |
Page.Run() | [PageHandler] |
Page.RunModal() | [ModalPageHandler] |
Report.Run() or Report.RunModal() | [ReportHandler] |
| Report request page | [RequestPageHandler] |
Hyperlink() | [HyperlinkHandler] |
Notification.Send() | [SendNotificationHandler] |
3. Analyze TableRelation Constraints
CRITICAL: Tests fail with validation errors when inserting data that violates TableRelation constraints.
Before inserting test data:
- Read the table definition for all fields receiving values
- Identify fields with
TableRelationproperties - Ensure related records exist before inserting test data
- Use Library functions (e.g.,
LibrarySales,LibraryPurchase) to create prerequisite data
4. Write Test Structure
Follow the AAA pattern (Arrange-Act-Assert):
[Test]
[HandlerFunctions('RequiredHandlers')]
procedure TestProcedureName()
begin
// [GIVEN] Setup test data and preconditions
Initialize();
CreateTestData();
// [WHEN] Execute the action being tested
ExecuteAction();
// [THEN] Verify the expected results
VerifyResults();
end;5. Handler Method Signatures
[ConfirmHandler]
procedure ConfirmHandlerYes(Question: Text[1024]; var Reply: Boolean)
begin
Reply := true;
end;
[MessageHandler]
procedure MessageHandler(Message: Text[1024])
begin
// Empty - suppresses message display
end;
[ModalPageHandler]
procedure ModalPageHandler(var TestPage: TestPage "Page Name")
begin
TestPage.OK().Invoke();
end;6. Best Practices
- Use descriptive test procedure names that explain what is being tested
- One assertion concept per test
- Use Library Variable Storage to pass data between handlers and tests
- Do NOT verify values inside handler procedures
- Clean up test data in teardown or use transaction rollback
- Use
Initialize()procedure to set up common test fixtures
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

