| bc-version |
domain |
keywords |
technologies |
countries |
application-area |
|
|
testing |
| test |
| library |
| setup |
| initialize |
| suppresscommit |
| asserterror |
|
|
|
|
Description
In CURABIS test apps, all test setup is centralized in a dedicated Test Library
codeunit (e.g. SV Test Library). Individual test procedures must not call
BC standard library codeunits (LibrarySales, LibraryInventory, etc.) directly.
Additionally, two rules apply to every test that calls a posting codeunit:
SetSuppressCommit(true) must be called before Run() to prevent data
from leaking between tests.
asserterror must always be followed by Assert.ExpectedErrorCode() or
Assert.ExpectedError() — a naked asserterror passes on any error,
not just the expected one.
Anti Pattern
// WRONG: inline setup bypassing the test library
procedure MyTest()
var
Item: Record Item;
begin
LibraryInventory.CreateItem(Item); // do not call directly
// ...
end;
// WRONG: posting without SuppressCommit
SVPost.Run(SVHeader); // commits to test database
// WRONG: naked asserterror
asserterror SVPost.Run(SVHeader);
// no assertion follows — passes on any error
Best Practice
// CORRECT: delegate to test library
procedure MyTest()
var
Item: Record Item;
begin
SVLib.GivenScrapItem(Item); // test library owns setup
// ...
end;
// CORRECT: SuppressCommit before Run
SVPost.SetSuppressCommit(true);
SVPost.Run(SVHeader);
// CORRECT: asserterror followed by assertion
asserterror SVPost.Run(SVHeader);
Assert.ExpectedErrorCode('Dialog');