Repository navigation
knowledge(testing): ExpectedError must identify the intended error - #280
Merged
Jesper Schulz-Wedde (JesperSchulz) merged 1 commit intoNov 19, 2026
Conversation
…ubstring matching and code-only checks Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Jesper Schulz-Wedde (JesperSchulz)
approved these changes
Nov 19, 2026
Jesper Schulz-Wedde (JesperSchulz)
left a comment
Contributor
There was a problem hiding this comment.
Looks good: the assertion now has to distinguish the intended error, while reusable helpers and the rollback-sentinel exception remain supported.
Jesper Schulz-Wedde (JesperSchulz)
merged commit Nov 19, 2026
b4613ea
into
microsoft:main
7 checks passed
Michael Dieringer (MichaelDieringer)
deleted the
community-contribution/testing-expected-error-identifies-error
branch
November 20, 2026 14:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
This sharpens
microsoft/knowledge/testing/asserterror-needs-expectederror-and-code. The article only edits Markdown; the samples are unchanged.The current text accepts
Assert.ExpectedError"with a stable substring". Many error tests take that literally, and the test stays green when the wrong error fires. The change has two parts.Best Practice now asks for text that only the intended error produces. Ideally that is the full
Labelwith its arguments, built withStrSubstNo. It also states two facts:Assert.ExpectedErrorandAssert.ExpectedErrorCodematch by substring.ExpectedErrorCodeon its own identifies only the kind of error.Anti Pattern adds three checks that look like verification but cannot tell one error from another:
ExpectedErrorCodealone;GetLastErrorText();ExpectedErrorfragment that several messages on the same code path contain.In each case, the test stays green when an earlier validation starts to fire instead of the one under test.
Facts checked against BCApps
Library Assert(Test Framework/Test Libraries/Assert/src/LibraryAssert.Codeunit.al),ExpectedErrortestsStrPos(GetLastErrorText(), Expected) = 0, andExpectedErrorCodetestsStrPos(GetLastErrorCode(), Expected) = 0.Errorshare one code: this is not stated on Microsoft Learn. BCApps' own W1 tests rely on it, withExpectedErrorCode('Dialog')afterError-raised failures (159 occurrences in 63 files). The text says "identifies only the kind of error" and does not name the code value.Evidence
This comes from a static read of production AL test suites (2026-11-18). In two apps, a large share of error tests (about 55 of 142, and 9 of 31) used one of the three weak forms above, or a bare
asserterror. The third app had too few error tests to count.Checks
validate_frontmatter.pyTest-ReviewFixtures.ps1Test-ReviewContract.ps1Applies to all BC versions. The domain is testing, the same as the article it sharpens.