Example: CheckErrors
The following code overrides the CheckErrors method. The purpose of this method is to examine errors generated by a production. In this case the code examines the errors generated by Tutorial.ExampleOperation after OnAfterProductionStart sends it the second message. The code does the following:
-
Uses GetEventLog to retrieve all of the errors from the event log. The class documentation for %UnitTest.TestProductionOpens in a new tab completely describes the method and its arguments. Here we supply three arguments to the method:
-
“error”—specifies the type of Event Log entry to retrieve. Other possible values include: “info”, “infouser”, “trace”, “alert”, and so on.
-
Log—passed by reference, this argument contains Event Log information when the method returns.
-
New—passed by reference, this argument contains the number of new Event Log entries.
-
-
Verifies that there are three new entries by examining the contents of new. Note that in this example there should be three new errors in the Event Log: one generated by each of Tutorial.ExampleOperation, the testing process, and the testing service.
-
Verifies that the error message contains “Test error case”. Note that “[” is the ObjectScript contains operator.
Method CheckErrors() As %Status
{
Set tSC = $$$OK
Set s = ..GetEventLog("error","","",.err,.new)
Set s1 = $$$AssertEquals(new,3,"Should be 3 new errors(found: "_+$Get(new)_")")
Set text = $Get(err(1,"Text"))
Set eText = "Test error case"
Set s2 =
$$$AssertTrue(text[eText,"Should contain '"_eText_"'(found: '"_text_"')")
if 's1||'s2 set tSC=..Error("Expected error entries don't match")
Return tSC
}
TestControl invokes CheckErrors only if the value of the IGNOREPRODUCTIONERRORS parameter of the test class is 1.