mirror of
https://github.com/microsoft/BCQuality.git
synced 2026-08-06 09:26:52 +01:00
Add 3 testing knowledge files from book review
- test-one-when-per-test: one WHEN per test, split if multiple actions - ui-test-codeunit-naming: _UT suffix for TestPage-based codeunits - test-feature-scenario-tags: [FEATURE]/[SCENARIO] comment structure Based on patterns from Automatiserede tests med Business Central (Dieringer). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
935d756f05
commit
f058095dec
3 changed files with 294 additions and 0 deletions
102
custom/knowledge/testing/ui-test-codeunit-naming.md
Normal file
102
custom/knowledge/testing/ui-test-codeunit-naming.md
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
---
|
||||
bc-version: [all]
|
||||
domain: testing
|
||||
keywords: [test, ui, testpage, naming, suffix, codeunit, page-testing]
|
||||
technologies: [al]
|
||||
countries: [w1]
|
||||
application-area: [all]
|
||||
---
|
||||
|
||||
## Description
|
||||
|
||||
Test codeunits that interact with pages via `TestPage` must carry a `_UT` suffix
|
||||
(Unit Test — UI layer) in their name. This distinguishes them from codeunits that
|
||||
test business logic directly by calling codeunit/table procedures.
|
||||
|
||||
The suffix signals to every reader that the codeunit opens pages, uses
|
||||
`TestPage.OpenNew()`, reads FactBox parts, or drives field validates through
|
||||
the page's `OnValidate` triggers — i.e. it exercises the UI layer, not just
|
||||
the logic layer.
|
||||
|
||||
**Convention:**
|
||||
|
||||
| Layer tested | Suffix | Example |
|
||||
|---|---|---|
|
||||
| Business logic (codeunits, tables) | *(none)* | `FindPriceTesting` |
|
||||
| Page / UI layer (`TestPage`) | `_UT` | `FindPriceTesting_UT` |
|
||||
|
||||
A codeunit may contain **only** UI tests or **only** logic tests — never mix both
|
||||
in the same codeunit.
|
||||
|
||||
## Anti Pattern
|
||||
|
||||
```al
|
||||
// WRONG: UI test codeunit without _UT suffix
|
||||
codeunit 99007 "Find Price Page Testing"
|
||||
{
|
||||
Subtype = Test;
|
||||
// contains TestPage calls — should be named "Find Price Testing_UT"
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
```al
|
||||
// WRONG: mixing direct codeunit calls and TestPage calls in the same codeunit
|
||||
codeunit 99007 "Find Price Testing"
|
||||
{
|
||||
Subtype = Test;
|
||||
|
||||
[Test]
|
||||
procedure GetPrice_LogicTest() // logic test — fine here
|
||||
begin
|
||||
FindPriceMgt.GetSalesPrice(...);
|
||||
end;
|
||||
|
||||
[Test]
|
||||
procedure Page_ShowsPrice_UT() // UI test — belongs in separate _UT codeunit
|
||||
var
|
||||
FindPricePage: TestPage "Find Price";
|
||||
begin
|
||||
FindPricePage.OpenNew();
|
||||
...
|
||||
end;
|
||||
}
|
||||
```
|
||||
|
||||
## Best Practice
|
||||
|
||||
```al
|
||||
// CORRECT: separate codeunits per layer
|
||||
|
||||
// Logic tests — no _UT suffix
|
||||
codeunit 99006 "Find Price Testing"
|
||||
{
|
||||
Subtype = Test;
|
||||
[Test]
|
||||
procedure GetPrice_CustomerPrice_ReturnsUnitPrice()
|
||||
begin
|
||||
FindPriceMgt.GetSalesPrice(...);
|
||||
end;
|
||||
}
|
||||
|
||||
// UI tests — _UT suffix
|
||||
codeunit 99007 "Find Price Testing_UT"
|
||||
{
|
||||
Subtype = Test;
|
||||
[Test]
|
||||
procedure Page_EnterCustomerAndItem_FactBoxShowsPrice()
|
||||
var
|
||||
FindPricePage: TestPage "Find Price";
|
||||
begin
|
||||
FindPricePage.OpenNew();
|
||||
FindPricePage.CustomerNo.SetValue(Customer."No.");
|
||||
FindPricePage.ItemNo.SetValue(Item."No.");
|
||||
Assert.AreEqual('100,00', FindPricePage.FindPriceInfo.UnitPrice.Value(), '');
|
||||
end;
|
||||
}
|
||||
```
|
||||
|
||||
## Object ID allocation
|
||||
|
||||
Allocate adjacent IDs for the two related codeunits (e.g. 99006 logic, 99007 UI)
|
||||
so they sort together in the object list and their relationship is self-evident.
|
||||
Loading…
Add table
Add a link
Reference in a new issue