Repository navigation
3 AL/BC testing patterns from an external BC testing expert's blog (Luc van Vugt, fluxxus.nl) - #159
Conversation
There was a problem hiding this comment.
Thanks for this — the mining quality is high. Verifying the Table Relation Test pattern against BCApps source instead of taking the blog's word for it is exactly the right instinct, and rejecting two candidates (one for no longer existing in current source) is the kind of restraint this corpus needs.
I re-verified all four claims independently. All four are factually correct.
| Claim | Verified against |
|---|---|
ConfirmHandler receives the raw template |
Reproduced in the source blog; corroborated by microsoft/ALAppExtensions#23935 |
| Table Relation Test exclusion hook | codeunit 134926, exact path; OnAfterRemoveTableRelation is an [IntegrationEvent] and RemoveTableRelation is public with the exact 5-arg signature |
Commit() in a lazy Initialize() |
778 BCApps test files use this exact pattern |
Assert.IsFalse over asserterror |
IsFalse exists in both Assert and Library Assert (130002) |
The table-relation article is the strongest of the four: the pattern only works because RemoveTableRelation is public rather than local, and the bad sample's claim that passing 0 widens the delete is correct — RemoveTableRelation skips SetRange for any zero argument. Samples are independently written rather than copied, and each good/bad pair differs in exactly one thing.
Validation is green locally: frontmatter 0 errors, knowledge index deterministic at 304 articles, 34 review fixtures across 17 domains.
Requesting changes on the following.
1. CLA (blocking)
license/cla is still pending. Please sign it — but note this isn't purely procedural here. The CLA's Originality of Work clause asks that contributions derived from a third party be accompanied by the phrase "Submission containing materials of a third party:" followed by the third-party name and any known licenses. Since this batch is explicitly derived from a named author's blog, that clause is genuinely engaged rather than boilerplate. Please include it when you sign.
2. commit-shared-test-fixture-inside-lazy-initialize.md contradicts existing guidance
This is the one substantive issue. The existing microsoft/knowledge/testing/transactionmodel-attribute-governs-test-transactions.md states that applying AutoRollback to a test whose code calls Commit "produces a runtime error on the first Commit... the test does not complete." Your new article instructs the reader to call Commit() inside Initialize() under exactly that default.
Both files are domain: testing, bc-version: [all], countries: [w1], application-area: [all] — identical applicability with incompatible normative guidance, which is precisely the shape READ's conflict detection is meant to catch. It also has a live consequence: al-testing-review.md already tells agents to flag code that "calls Commit under AutoRollback", so as things stand an agent would flag the canonical BCApps fixture pattern.
The evidence says your article is right and the existing one overstates. src/Layers/W1/Tests/ERM/ERMOnlineMappingSetup.Codeunit.al commits inside Initialize(), declares no TransactionModel attribute at all, and passes — along with 777 other test files.
Since this PR is what surfaces the conflict, please correct the overstatement in transactionmodel-attribute-governs-test-transactions.md as part of this change, so the two articles agree.
3. confirm-needs-strsubstno... presents a platform bug as designed behavior
The article explains that substitution happens "only for the dialog a real user sees," which reads as intended platform behavior. It isn't — it's a reported defect (microsoft/ALAppExtensions#23935), raised by Luc van Vugt himself, with an internal bug filed at the time by Nikola Kukrika (@nikolakukrika).
That issue was closed as COMPLETED in February 2024, but the thread contains no fix confirmation and I found no public release-note evidence either way, so the current status is genuinely unclear. With bc-version: [all] and a Best Practice that tells agents to restructure production code, a silent platform fix would turn this into agents rewriting correct code for no reason.
Please reframe it as a known platform defect with the issue linked. Nikola Kukrika (@nikolakukrika) — since you filed the internal bug and own this folder, could you confirm its disposition before we ship this as unbounded guidance?
Worth adding while you're in there: per the source blog, Message/MessageHandler substitutes correctly and only Confirm is affected. That asymmetry is both good evidence it's a bug and useful protection against an agent over-generalizing the rule to MessageHandler.
4. Minor — table-relation-test-exclude-known-invalid-relations-via-event.md
- Codeunit 134926 ships in BCApps' test app, so only consumers depending on the BC test libraries can subscribe. Worth stating explicitly.
- "walks every
TableRelationfield property in the app" is slightly off — it readsTable Relations Metadatafiltered to1..1999999999, i.e. tenant-wide across installed apps, not just the current app. - No token in
al-testing-review.mdcoversTableRelationorOnAfterRemoveTableRelation, so this article may never surface in review. The other three are already reachable viaConfirmHandler,asserterror,Commit, andLibrary Assert. Happy to add the tokens separately if you'd rather keep this PR scoped to knowledge.
Note that /microsoft/knowledge/testing/ is owned by Nikola Kukrika (@nikolakukrika), ventselartur and Bugsy (@pchriste-microsoft-com), so this needs one of them to approve regardless of my review. Only flag and guard have run so far — the frontmatter and index workflows still need to go green in CI once a maintainer approves the run.
Nice work overall. Item 1 is quick; 2 and 3 are the ones that need real attention.
|
@microsoft-github-policy-service agree [company="CURABIS ApS"] Submission containing materials of a third party: Luc van Vugt (fluxxus.nl) - blog content, no explicit license found. |
|
Point 1: the fast one... done... Point 2: Verified directly in ERMOnlineMappingSetup.Codeunit.al (codeunit 134915). No TransactionModel attribute at all, Commit() inside Initialize(), and manual cleanup via asserterror Error(...) at the end rather than relying on automatic rollback. Point 3: Checked the issue directly. No fix confirmation visible in the thread either, just closed as completed with no comment. Will reframe as a known, unconfirmed platform defect with the issue linked, and add the Message/MessageHandler asymmetry as supporting evidence per your note. Point 4: Fair, will note the test-app dependency explicitly, correct the "every TableRelation field property" wording to the actual tenant-wide Table Relations Metadata scope, and add the missing al-testing-review.md tokens in this PR rather than leaving it unreachable. |
|
@microsoft-github-policy-service agree company="CURABIS ApS" Submission containing materials of a third party: Luc van Vugt (fluxxus.nl) - blog content, no explicit license found. |
- transactionmodel-attribute-governs-test-transactions.md: the "Commit causes an error" behavior is specific to an explicitly declared AutoRollback attribute. A test method with no TransactionModel attribute at all is a distinct, valid shape — BCApps' own codeunit 134915 "ERM Online Mapping Setup" commits inside a lazy Initialize() with no attribute declared, cleaning up via a manual asserterror at the end. Evidence for commit-shared-test-fixture- inside-lazy-initialize.md (this PR), which is correct as submitted. - confirm-needs-strsubstno-before-confirmhandler-sees-substituted-text.md: reframe as a known, unconfirmed-fix platform defect (microsoft/ALAppExtensions#23935) rather than designed behavior; add the Message/MessageHandler asymmetry as supporting evidence. - table-relation-test-exclude-known-invalid-relations-via-event.md: note the test-app-only consumer dependency; correct "walks every TableRelation field property in the app" to the actual tenant-wide Table Relations Metadata scope across installed apps. - Wire confirm-needs-strsubstno, commit-shared-test-fixture-inside- lazy-initialize, and table-relation-test-exclude-known-invalid- relations-via-event into al-testing-review.md's candidate-selection cues. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Jesper Schulz-Wedde (JesperSchulz)
left a comment
There was a problem hiding this comment.
Follow-up after 1e22b51: CLA/disclosure now pass, and the Table Relation dependency and tenant-wide metadata wording are improved. The remaining transaction, applicability, fixture, and routing issues are inline.
Please also preserve durable provenance in the knowledge files themselves: each externally inspired article should identify its specific source and what was derived from it. A PR-level disclosure is useful for CLA review but will not accompany the rule when an agent consumes it later.
|
Correction to my own review. The transaction analysis in my first round was wrong, and I would rather retract it explicitly than leave it standing next to a follow-up that contradicts it. What I got wrongIn the first round I wrote that "the evidence says your article is right and the existing one overstates", and asked you to correct The fact
Worth noting for anyone following this thread: the TransactionModel attribute page — the one you naturally reach for — never names a default at all. That is probably how this got past both of us. Why my evidence never supported my conclusion
I counted 778 files sharing the pattern and treated that as confirming the article's stated mechanism. Prevalence of a practice is not evidence for the reason given for it — and that distinction is most of what this corpus is for. The giveaway was in the file I quoted. It ends with a deliberate What this means for the PR
One more from my first roundI wrote that the ConfirmHandler issue was "raised by Luc van Vugt himself". microsoft/ALAppExtensions#23935 was opened by Matjaž Šega; Luc blogged it and credited Malcolm Gray. My follow-up corrected that inline, but the error originated in the round that presented a table asserting I had independently verified all four claims and that all four were factually correct. That table was overconfident. One of the four has since been ruled incorrect, and one of its supporting attributions was wrong. I would rather say so plainly, since "verified against source" is the bar this repository asks contributors to meet. UnaffectedNothing here touches the other three articles, and the table-relation facts I checked in the first round all hold: codeunit 134926, Sorry for the churn. This one was my error, not yours. |
|
Appreciate the correction — no worries on the churn. 0b08c2f reflects it: the |
|
Jesper Schulz-Wedde (@JesperSchulz) Addressed this round in 0b08c2f (pushed 2026-09-08): the 6 inline issues above, the transaction-model contradiction from your retraction (both articles now state and agree on the |
Jesper Schulz-Wedde (JesperSchulz)
left a comment
There was a problem hiding this comment.
Thank you for the substantial rewrite. The Confirm rule removal, TransactionModel correction, OnPrem scope, Boolean-rule precedence, routing, and per-article attribution address most of the previous feedback.
The remaining transaction concerns are tracked in the existing conversation, so I am not opening duplicate threads for them. One additional factual qualification is needed below because it changes which table relations the article tells agents to reject. We recognize the extra round is inconvenient; this is limited to behavior that materially affects the rule's correctness. The branch also currently conflicts with main in the TransactionModel article and testing review skill and will need to be updated before merge.
Jesper Schulz-Wedde (JesperSchulz)
left a comment
There was a problem hiding this comment.
Re-reviewed the full latest diff and every prior thread. The deleted Confirm rule, provenance/CLA attribution, OnPrem boundary, narrow exclusion API, Boolean article scope, and candidate cues are otherwise sound. The exact-head frontmatter, index determinism (303 articles), and 34 fixtures/17 domains all pass locally; flag, guard, and CLA pass.
Changes still needed:
- Shared fixture: resolve the three items left in the existing thread—recommend
TestIsolation = Codeunit(not bareDisabled), exclude the deliberate rollback sentinel from the generic ExpectedError rule, and replace the non-demonstrating fixtures with persisted data + a later test + explicit runner/isolation context. - Table Relation Test: document both conditional-only exceptions from codeunit 134926: source length may exceed the maximum related length, and a required
Coderelation accepts aCodeorTextsource. Unconditional relations remain exact-length/exact-type. - Deterministic routing:
al-testing-review.mdcurrently excludes everyasserterror Assert.IsTrue/IsFalseBoolean-returning shape from the generic rule, while the new article's Scope says the generic rule still owns cases where the guarded call itself is expected to error. Qualify the cue so the specialized rule wins only when the construct solely inverts the returned Boolean. - Resolve the current conflict with
mainintransactionmodel-attribute-governs-test-transactions.md, and update the stale PR title/summary from four patterns to the three surviving ones (remove the deleted Confirm claim).
These are the remaining correctness/mergeability issues; no additional round is intended beyond verifying those exact fixes.
Fourth batch from CURABIS ApS, mined from an external BC/NAV testing expert's blog archive (fluxxus.nl). Confirm+StrSubstNo interaction with ConfirmHandler, Table Relation Test's OnAfterRemoveTableRelation exclusion hook (verified against BCApps source, codeunit 134926), committing shared lazy-Initialize fixture data, and Assert.IsFalse vs asserterror for boolean checks.
- transactionmodel-attribute-governs-test-transactions.md: the "Commit causes an error" behavior is specific to an explicitly declared AutoRollback attribute. A test method with no TransactionModel attribute at all is a distinct, valid shape — BCApps' own codeunit 134915 "ERM Online Mapping Setup" commits inside a lazy Initialize() with no attribute declared, cleaning up via a manual asserterror at the end. Evidence for commit-shared-test-fixture- inside-lazy-initialize.md (this PR), which is correct as submitted. - confirm-needs-strsubstno-before-confirmhandler-sees-substituted-text.md: reframe as a known, unconfirmed-fix platform defect (microsoft/ALAppExtensions#23935) rather than designed behavior; add the Message/MessageHandler asymmetry as supporting evidence. - table-relation-test-exclude-known-invalid-relations-via-event.md: note the test-app-only consumer dependency; correct "walks every TableRelation field property in the app" to the actual tenant-wide Table Relations Metadata scope across installed apps. - Wire confirm-needs-strsubstno, commit-shared-test-fixture-inside- lazy-initialize, and table-relation-test-exclude-known-invalid- relations-via-event into al-testing-review.md's candidate-selection cues. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
- commit-shared-test-fixture-inside-lazy-initialize.md: fundamentally rewritten. AutoCommit is the documented default TransactionModel, not AutoRollback. Explains the real mechanism (Commit() protects a fixture from the test method's own later deliberate rollback, per Codeunit.Run/ TransactionModel-property semantics) and the TestIsolation dependency (Disabled/Codeunit survive across methods, Function does not). Fixtures rewritten to demonstrate the actual failure/success shape. - transactionmodel-attribute-governs-test-transactions.md: now states the AutoCommit default explicitly and agrees with the article above, closing the contradiction Jesper flagged between the two testing articles. - Deleted confirm-needs-strsubstno-before-confirmhandler-sees-substituted-text (.md/.good.al/.bad.al): the underlying platform bug (microsoft/ ALAppExtensions#23935) was closed as completed in Feb 2024; cannot be reproduced or bc-version-pinned on any currently supported version. - table-relation-test-exclude-known-invalid-relations-via-event.md: added the [Scope('OnPrem')] boundary verified against BCApps' Table Relation Test codeunit. - use-assert-isfalse-not-asserterror-for-boolean-checks.md: added a Scope section resolving the overlap with asserterror-needs-expectederror-and-code. - al-testing-review.md: fixed the shared-fixture cue to catch the actual anti-pattern instead of the compliant shape, added the missing cue for use-assert-isfalse-not-asserterror-for-boolean-checks, wired precedence between it and the generic asserterror rule, and removed the cue for the deleted article. - Added in-file Source provenance (specific fluxxus.nl post per article, with what was independently verified vs. taken from the post) to the three surviving externally-inspired articles, per Jesper's request that provenance live in the knowledge file itself, not only the PR description. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
- commit-shared-test-fixture-inside-lazy-initialize: three sub-issues.
Recommended TestIsolation = Codeunit instead of listing Disabled as an
equal option - Disabled never rolls back at all ("tests are not
isolated from each other" per the property's own docs), so a fixture
this pattern commits under Disabled is permanent database
contamination unless something else tears it down; Disabled is now
only mentioned alongside that explicit teardown requirement. Added
precedence in al-testing-review.md so the deliberate end-of-test
asserterror Error(...) rollback sentinel isn't also flagged by the
generic asserterror-needs-expectederror-and-code rule. Rewrote both
fixtures to actually demonstrate the pattern: persisted fixture data
(an Item record) instead of an empty comment, a second [Test] method
that depends on the fixture surviving into it, and an explicit
Subtype = TestRunner / TestIsolation = Codeunit runner codeunit.
- table-relation-test-exclude-known-invalid-relations-via-event:
the length/type rule was stated as one global requirement. Verified
ValidateFieldRelation in codeunit 134926 directly (BCApps reference
clone) and split it into the two branches the source actually has:
a field with any unconditional relation needs exact length and exact
resolved type; a field whose relations are all conditional only fails
on being shorter (longer is fine) than the largest related field, and
when the required type is specifically Code, a Text source passes too
- a tolerance that does not apply on the unconditional side and does
not extend to a required Text.
Rebased onto upstream/main (one conflict in
transactionmodel-attribute-governs-test-transactions.md - upstream had
already linked its sample references via the READ convention, ours
added a Source section; merged both). Also converted the 3 remaining
plain-backtick sample references in this PR to the READ-convention
markdown-link form, same fix as microsoft#156/microsoft#157/microsoft#158.
0b08c2f to
69b09db
Compare
|
Thanks Jesper. Addressed all four items from the 2026-09-15 re-review. 1. Shared fixture (
2. Table Relation Test length/type rule: verified 3. Deterministic routing: already resolved in the prior round per your read — no further change needed there. 4. Rebase + stale title: rebased onto current Also converted the 3 remaining plain-backtick sample references in this PR to the READ-convention markdown-link form, same fix as #156/#157/#158. All local validators pass clean: frontmatter (0 errors, 0 warnings), knowledge-index, knowledge-retrieval (336 articles / 563 samples), review-fixtures (108 cases / 20 leaf domains), skill-index. |
Jesper Schulz-Wedde (JesperSchulz)
left a comment
There was a problem hiding this comment.
Four merge-critical issues remain:
-
In
al-testing-review.md, the generic ExpectedError route excludes everyasserterror Assert.IsTrue/IsFalsearound a Boolean-returning call, while the specialized route accepts only constructs used solely to invert the Boolean. A test expecting the guarded Boolean function itself to raise therefore falls through both routes. Narrow the exclusion to the same inversion-only condition. -
The rollback-sentinel exception exists only in skill prose while
asserterror-needs-expectederror-and-code.mdremains unconditional. False-positive exclusions are normative knowledge and must be encoded there so every consumer avoids the harmful recommendation. -
commit-shared-test-fixture-inside-lazy-initialize.good.alhand-rolls an Item withInit, an invented key, andInsert(true), which another active rule correctly flags. UseLibraryInventory.CreateItemso the canonical fix is clean under the full ruleset. -
table-relation-test-exclude-known-invalid-relations-via-event.good.aland its bad pair reference undefinedSample HeaderandSample Setuptables. The samples are not self-contained or compilable; define minimal tables or use existing symbols.
|
The transaction-model rewrite is materially stronger. I left two discussions open because they still contain active contract details; the latest review makes the remaining fixes explicit and finite. |
- al-testing-review.md: the generic ExpectedError cue's asserterror Assert.IsTrue/IsFalse exclusion was unconditional, but the specialized rule it deferred to only claims the pure-inversion shape. A test expecting the guarded Boolean-returning call itself to raise fell through both routes. Narrowed the exclusion to the same inversion-only condition the specialized cue already uses. - asserterror-needs-expectederror-and-code.md: the rollback-sentinel exception (a trailing asserterror Error(...) used purely to force a fixture rollback, not to verify a specific failure) previously lived only in skill routing prose. Encoded it directly in the article's Anti Pattern section so every consumer of the knowledge base sees it, not just this one skill. - commit-shared-test-fixture-inside-lazy-initialize.good.al/.bad.al: replaced hand-rolled Item.Init()/Insert(true) with LibraryInventory.CreateItem, so the canonical fixture doesn't itself trigger use-library-codeunits-for-test-fixtures. - table-relation-test-exclude-known-invalid-relations-via-event.good.al/ .bad.al: declared minimal "Sample Setup"/"Sample Header" tables inline instead of referencing undefined symbols, matching this repo's own convention that every fixture is self-contained.
|
Thanks Jesper. All four fixed:
Validators pass clean. |
Jesper Schulz-Wedde (JesperSchulz)
left a comment
There was a problem hiding this comment.
One merge-critical fixture issue remains. The new Sample Header."Category Code" field has no TableRelation, so the good subscriber's targeted RemoveTableRelation removes no metadata. The bad sample also has no second valid relation whose coverage its table-wide removal would destroy. The pair therefore demonstrates neither the recommended exclusion nor its anti-pattern.
Please add an actual relation that creates the targeted metadata row and another valid relation on the same table that remains checked by the good subscriber but is incorrectly removed by the bad subscriber. The four blockers from the latest review are otherwise resolved.
…one to protect
The "Category Code" field had no TableRelation at all, so the good
subscriber's RemoveTableRelation call targeted metadata that never
existed - a no-op. Added a real TableRelation to "Sample Setup" on
that field (the one known exception to exclude) and a second,
ordinary self-referencing relation ("Parent No." -> "Sample
Header"."No.") with no exception. The good fixture now removes only
the first; the bad fixture's table-wide removal (field/related
table/field all 0) now demonstrably also strips the second, showing
the actual anti-pattern instead of removing nothing meaningful.
|
Thanks Jesper. Fixed — you're right, "Category Code" had no `TableRelation` at all, so the good subscriber's `RemoveTableRelation` call targeted metadata that never existed. Added a real `TableRelation = "Sample Setup"."Primary Key"` on "Category Code" (the one known exception to exclude) and a second, ordinary self-referencing relation, `"Parent No." -> "Sample Header"."No."`, with no exception. The good fixture's targeted `RemoveTableRelation(..., 10, ...)` now removes only the first; the bad fixture's table-wide `RemoveTableRelation(..., 0, 0, 0)` now demonstrably also strips the second — so the pair actually shows both the recommended exclusion and its anti-pattern. Validators pass clean. |
Jesper Schulz-Wedde (JesperSchulz)
left a comment
There was a problem hiding this comment.
The final fixture blocker is resolved: the good sample removes one real relation metadata row while preserving a second valid relation, and the bad sample demonstrably removes both. The earlier transaction, routing, knowledge-contract, fixture-library, and table-relation semantics issues are also resolved. No new merge-critical issue found.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
The merge conflict has been resolved and fully validated. Because GitHub reports Please merge that small sync PR. It applies validated merge commit |
Resolve BCQuality microsoft#159 merge conflicts
…ugt-blog-patterns Resolve al-testing-review.md by union: keep both main's additions from microsoft#196 and this PR's already-approved changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
830eaff
into
microsoft:main
|
Thanks Jesper — Curabis#3 is merged. Resolution is a plain union: #196's new On the merged tree: |
…crosoft#198, microsoft#202) into document-distribution-batch Resolve evaluation/review-fixtures.json semantically: data-modeling articles list is the union of main's list and this PR's nine articles; everything else is taken from main unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Fourth batch from CURABIS ApS, this time mined from a source outside CURABIS itself: Luc van Vugt's fluxxus.nl, a long-running blog by a BC/NAV developer who authored a book on automated testing and ATDD in Business Central. The blog runs 2009–2023 and is mostly legacy classic-client/C-AL content; these 3 are the patterns that survived review, are still current in modern AL, and cleared BCQuality's admission test.
OnAfterRemoveTableRelationexclusion hook — verified directly against BCApps source (codeunit 134926 "Table Relation Test",src/Layers/W1/Tests/Misc/TableRelationTest.Codeunit.al) rather than taken on the blog's word alone.Initialize()fixture data needs an explicitCommit(), or it rolls back with the first test that creates it and silently vanishes for every test after.Assert.IsFalsefor a boolean check, notasserterrorwrapped aroundAssert.IsTrue—asserterrorverifies that an error was raised, not the value under test.A fourth candidate —
Confirm()+StrSubstNosubstitution timing — was removed during review: the underlying platform issue (microsoft/ALAppExtensions#23935) is closed as completed and could not be reproduced or pinned to any currently supported version, so an unconditional[all]workaround wasn't defensible.Two other candidates found during mining were rejected: a
TestPermissions::InheritFromTestCodeunitenum-value restriction (too thin/overlapping the existing permission-tests rule) and a suite-wide fixture-injection event pattern from 2018/2020 NAV content that no longer exists anywhere in current BCApps source (verified absent, not proposed).Test plan
🤖 Generated with Claude Code