%UnitTest.TestSqlScript
class %UnitTest.TestSqlScript extends %UnitTest.TestScript
The sample class mentioned here (Sample.Person) is part of https://github.com/intersystems/Samples-Data.Opens in a new tab See Downloading SamplesOpens in a new tab.
This class replays script-driven SQL tests. It provides an implementation of the runScript() method that reads and executes SQL statements from the script specified in the TESTFILE parameter, comparing it to a reference log of expected output. It also provides an implementation of the OnBeforeAllTests() method that populates the XML-enabled class under test (DATACLASS) from DATAFILE.To write a test, start by creating a subclass of this class with appropriate values for the DATACLASS, DATAFILE, and DATATAG parameters:
Class Sample.SqlTest extends %UnitTest.TestSqlScript { Parameter DATACLASS = "Sample.Person"; Parameter DATAFILE = "person.data"; Parameter DATATAG = "person"; }
Write ##class(Sample.Person).Populate(100)
Set writer=##class(%XML.Writer).%New() Set writer.Charset="UTF-8" Set sc=writer.OutputToFile("person.data") Set sc=writer.RootElement("people") Set statement=##class(%SQL.Statement).%New() Set sc=statement.%PrepareClassQuery("Sample.Person","Extent") Set result=statement.%Execute() While result.%Next(.sc) { Set id=result.%Get("ID") Set person=##class(Sample.Person).%OpenId(id) Set sc=writer.Object(person,"person") } Set sc=writer.EndRootElement() Set sc=writer.EndDocument()
select max(SSN) from Sample.Person #### select count(ID) from Sample.Person ####count IDs
- the script file (script.txt)
- a copy of the test class (Sample.SqlTest)
- a copy of the class under test (Sample.Person)
- the data file (person.data)
Do ##class(%UnitTest.Manager).RunTest("Sample",,"reference")
SQL> select max(SSN) from Sample.Person Aggregate_1: 992-27-1936: SQL> select count(ID) from Sample.Person Aggregate_1: 100: Test count IDs
Do ##class(%UnitTest.Manager).RunTest("Sample")
Method Inventory
Parameters
If CORRELATIONLIST, DATACLASS, and DATATAG are all specified, the DATATAG and DATACLASS pair are added to the end of the CORRELATIONLIST.
The default value of "" prevents elapsed time information from being displayed at the end of each SQL statement in the test. Setting it to 1 will display the result in seconds. Setting it to 10 will display elapsed time in multiples of 10 seconds. Setting it to 0.1 will display elapsed time to the nearest tenth second.
Methods
Inherited Members
Inherited Properties
Inherited Methods
- %AddToSaveSet()
- %ClassIsLatestVersion()
- %ClassName()
- %ConstructClone()
- %DispatchClassMethod()
- %DispatchGetModified()
- %DispatchGetProperty()
- %DispatchMethod()
- %DispatchSetModified()
- %DispatchSetMultidimProperty()
- %DispatchSetProperty()
- %Extends()
- %GetParameter()
- %IsA()
- %IsModified()
- %New()
- %NormalizeObject()
- %ObjectModified()
- %OnNew()
- %OriginalNamespace()
- %PackageName()
- %RemoveFromSaveSet()
- %SerializeObject()
- %SetModified()
- %ValidateObject()
- AssertEqualsViaMacro()
- AssertFailureViaMacro()
- AssertFilesSQLUnorderedSameViaMacro()
- AssertFilesSameViaMacro()
- AssertNotEqualsViaMacro()
- AssertNotTrueViaMacro()
- AssertSkippedViaMacro()
- AssertStatusEqualsViaMacro()
- AssertStatusNotOKViaMacro()
- AssertStatusOKViaMacro()
- AssertSuccessViaMacro()
- AssertTrueViaMacro()
- Checkout()
- LogMessage()
- OnAfterAllTests()
- OnAfterOneTest()
- OnBeforeOneTest()
- TestRunScript()