I hope everyone is well! I'm working on Automated Testing for Business Central for a codeunit with a method that evaluates the No. Series parameter.
In this method, I use the TestField method to ensure that Default Nos. are enabled:
NoSeries.TestField("Default Nos.", true);
Now for the Test codeunit. Amongst my global variables, I define NonDefaultNoSeries as my No. Series record.
My OnRun procedure calls a local procedure that initializes my No. Series using Library - Utility with Default disabled:
local procedure CreateNoSeries()
var
LibraryUtil: Codeunit "Library - Utility";
NoSeriesLine: Record "No. Series Line";
begin
LibraryUtil.CreateNoSeries(NonDefaultNoSeries, false, false, false);
LibraryUtil.CreateNoSeriesLine(NoSeriesLine, NonDefaultNoSeries.Code, '10001', '99999');
end;
Now that housekeeping is out of the way, I design a test to ensure the correct error arises with TestField method:
[Test]
[HandlerFunctions('ConfirmHandlerYes')]
procedure UPCMeth_NoSeriesValidation_NonDefault()
var
ErrLabel: Label 'Default Nos. must be equal to ''Yes'' in No. Series: Code=%1. Current value is ''No''.';
begin
// Using permissions that do not include Super.
LibraryLowerPermissions.SetO365BusFull();
// [GIVEN] A Postive No Series with Default disabled.
// [WHEN] UPC No. Series Validation is run.
// [THEN] Validation fails because No. Series Default is disabled.
asserterror UPCMeth.ValidateUPCNoSeries(NonDefaultNoSeries, false);
AssertThat.ExpectedError(StrSubstNo(ErrLabel, NonDefaultNoSeries.Code));
end;
Running my tests, I get an error for the Expect Error:
Assert.ExpectedError failed.
Expected: Default Nos. must be equal to 'Yes' in No. Series: Code=GU00000003. Current value is 'No'..
Actual: Default Nos. must be equal to 'Yes' in No. Series: Code=GU00000003. Current value is 'No'..
The text is virtually the same; so, I'm not sure what's going wrong here. Removing the Expected Error assertion resolves this problem.
I cannot drill into the TestField method to copy the error text label; so, I thought I would check with the community for feedback.
Is there anything I should do differently here? Is it even worth spending time to build tests around TestField?
I'm interested if there are any recommended resources describe best practices for automated testing in Business Central.
Thanks!

Report
All responses (
Answers (