mirror of
https://github.com/microsoft/BCQuality.git
synced 2026-10-05 14:46:55 +01:00
Add 4 more AL/BC testing patterns from Luc van Vugt's fluxxus.nl blog
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.
This commit is contained in:
parent
07e324ddbc
commit
12b7f73d24
12 changed files with 218 additions and 0 deletions
|
|
@ -0,0 +1,26 @@
|
|||
---
|
||||
bc-version: [all]
|
||||
domain: testing
|
||||
keywords: [initialize, isinitialized, shared-fixture, commit, autorollback, lazy-initialization]
|
||||
technologies: [al]
|
||||
countries: [w1]
|
||||
application-area: [all]
|
||||
---
|
||||
|
||||
# Commit shared fixture data created inside a lazy Initialize(), or later tests lose it
|
||||
|
||||
## Description
|
||||
|
||||
A test codeunit that creates master/setup data once, guarded by an `IsInitialized` flag, to avoid repeating expensive setup across many `[Test]` methods depends on that data surviving into every later test. Each `[Test]` method runs under `AutoRollback` by default, so data inserted during the first test's call to `Initialize()` rolls back at the end of that test. `IsInitialized` is a variable, not persisted data, so it still reads `true` on the next test — but the fixture rows it points to are already gone.
|
||||
|
||||
## Best Practice
|
||||
|
||||
Call `Commit()` at the end of a lazy/shared `Initialize()` procedure, once the shared fixture data is created, so it survives past the first test's rollback boundary. Pair this with a `TestIsolation`-enabled test runner so the committed fixture is still cleaned up at the end of the full run.
|
||||
|
||||
See sample: `commit-shared-test-fixture-inside-lazy-initialize.good.al`.
|
||||
|
||||
## Anti Pattern
|
||||
|
||||
A shared `Initialize()` guarded by `IsInitialized` that creates fixture records but never commits. The first test that runs it passes; every later test in the same codeunit either fails to find the fixture data or silently re-triggers setup logic that `IsInitialized` was meant to skip.
|
||||
|
||||
See sample: `commit-shared-test-fixture-inside-lazy-initialize.bad.al`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue