bcquality/community/knowledge/testing/tablerelation-requires-prerequisite-records.bad.al
Jesper Schulz-Wedde 6c02d68b4e Add testing knowledge: UI handlers, table relations, asserterror, fixtures (P1+P2)
Six BC-specific testing-domain knowledge articles in community/knowledge/testing/, each with .good.al/.bad.al samples:

- ui-calls-require-test-handlers
- tablerelation-requires-prerequisite-records
- handlers-enqueue-never-assert
- handlerfunctions-attribute-must-match-ui-path
- asserterror-needs-expectederror-and-code
- use-library-codeunits-for-test-fixtures

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-29 16:10:17 +02:00

32 lines
1.1 KiB
AL

codeunit 50403 "Test Table Relation Bad"
{
Subtype = Test;
[Test]
procedure SalesLineAcceptsExistingItem()
var
Customer: Record Customer;
SalesHeader: Record "Sales Header";
SalesLine: Record "Sales Line";
begin
LibrarySales.CreateCustomer(Customer);
LibrarySales.CreateSalesHeader(SalesHeader, SalesHeader."Document Type"::Order, Customer."No.");
// No item was created. Validating "No." against a non-existent item
// raises a TableRelation error here, aborting the test at runtime
// before any assertion runs.
SalesLine.Init();
SalesLine."Document Type" := SalesHeader."Document Type";
SalesLine."Document No." := SalesHeader."No.";
SalesLine."Line No." := 10000;
SalesLine.Type := SalesLine.Type::Item;
SalesLine.Validate("No.", 'GHOST');
SalesLine.Insert(true);
Assert.AreEqual('GHOST', SalesLine."No.", 'Unreachable: validation already failed.');
end;
var
Assert: Codeunit "Library Assert";
LibrarySales: Codeunit "Library - Sales";
}