agentleFS
MicrosoftKnown publishermicrosoft/BC-Bench/src/bcbench/agent/shared/instructions/microsoftInternal-NAV/skills/al-test-generation/SKILL.md

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.

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
  1. Distinctive:

    Before writing any test code:

    line 10
  2. Distinctive:

    Read and understand the procedure or functionality being tested

    line 11
  3. Distinctive:

    Look for these patterns in the code under test:

    line 19
  4. Distinctive:

    Before inserting test data:

    line 37
  5. Distinctive:

    Read the table definition for all fields receiving values

    line 38
  6. Distinctive:

    Ensure related records exist before inserting test data

    line 40
  7. Very specific:

    Use Library functions (e.g., LibrarySales, LibraryPurchase) to create prerequisite data

    line 41
  8. Distinctive:

    Follow the AAA pattern (Arrange-Act-Assert):

    line 45
  9. Distinctive:

    Use descriptive test procedure names that explain what is being tested

    line 88
  10. Distinctive:

    Use Library Variable Storage to pass data between handlers and tests

    line 90
  11. Distinctive:

    Do NOT verify values inside handler procedures

    line 91
  12. Very specific:

    Use Initialize() procedure to set up common test fixtures

    line 93

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

To create AL tests for Microsoft Dynamics 365 Business Central, follow this process:

1. Analyze the Code Under Test

Before writing any test code:

  1. Read and understand the procedure or functionality being tested
  2. Trace through all code paths to identify UI interactions
  3. 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 PatternRequired 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:

  1. Read the table definition for all fields receiving values
  2. Identify fields with TableRelation properties
  3. Ensure related records exist before inserting test data
  4. 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

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.