%UnitTest.Manager
class %UnitTest.Manager extends %Library.RegisteredObject
Launches tests using any of the following methods:RunTest: Runs a set of tests and deletes all test classes afterwards.
RunTestSuites: Same as RunTest, but requires 3 arguments, all of which can be null.
DebugRunTestCase: Can be used after DebugLoadTestSuite. It runs tests and does not delete the test classes afterwards, like RunTest does.
Setup: Set the global variable ^UnitTestRoot to a root directory that contains your test suites. This must point to a valid directory. Example: Set ^UnitTestRoot="C:\MyUnittests" (adding a final slash is optional).
Specifically, the RunTest method does the following:
- Loads and compiles any test files in the directory specified by the first argument, testspec.
If the loadxml qualifier is on, all .xml or .XML files will be loaded.
If the loadudl qualifier is on, all udl files will be loaded.
- For each class that is a subclass of %UnitTest.TestCase, RunTest
- Runs the OnBeforeAllTests() method
- For each method named Test*, such as TestXyz, RunTest
- Runs the method OnBeforeOneTest()
- Runs the method TestXyz()
- Runs the method OnAfterOneTest()
- Runs the method OnBeforeOneTest()
- Repeats steps i through iii for all the other methods named Test*
- Runs OnAfterAllTests() method
- Runs the OnBeforeAllTests() method
- Repeats steps A through D for each class that is a subclass of %UnitTest.TestCase.
- Deletes all the classes loaded during execution.
- Repeats step 1 through 4 recursively (for all sub-directories) through the specified directory (assuming that the /recursive qualifier is on and skipping any directory whose name begins with an underscore).
Unit test logs testcase output to the global ^UnitTest.Result. Results displayed on CSP pages come from this global.
Property Inventory
Method Inventory
- Cleanup()
- ConvertLogData()
- ConvertStatus()
- DebugLoadTestSuite()
- DebugRunTestCase()
- GetSubDirectories()
- GetTestState()
- GetTestStatus()
- IsSuccess()
- LogAssert()
- LogMessage()
- LogStateBegin()
- LogStateEnd()
- LogStateStatus()
- OnAfterAllTests()
- OnAfterOneTest()
- OnAfterSaveResult()
- OnAfterTestCase()
- OnAfterTestSuite()
- OnBeforeAllTests()
- OnBeforeAutoLoad()
- OnBeforeOneTest()
- OnBeforeTestCase()
- OnBeforeTestSuite()
- PrintErrorLine()
- PrintLine()
- PrintURL()
- PurgeLog()
- PurgeResult()
- Record()
- Root()
- RunOneTestCase()
- RunOneTestSuite()
- RunTest()
- RunTestSuites()
- RunTestsFromFileList()
- SaveResult()
- WipeNamespace()
- addToExcludeGlobal()
- deleteLoadedClasses()
- getLoadedClass()
- setRecursiveStatus()
Properties
Methods
pLogIndex is the test instance index in ^UnitTestLog.
pResultNamespace is the namespace for ^UnitTest.Result.
pMachine, pConfiguration, pVersion and pUserParam are the new information ^UnitTest.Result collects but ^UnitTestLog does not. You can provide this information manually here when doing the conversion.
pUserParam is used the same way as the userparam argument which is the 3rd argument to the RunTest method. The top node of pUserParam becomes UserParam and the first level subscripts and their values are used to populate the UserFields array.
- testspec
- testspec takes the form of testsuite [ :testcase [ :testmethod ] [ ;testcase [ :testmethod ] ]* ].
testsuite is a directory (and optionally, subdirectories) that contains tests. By default RunTest runs all tests found here recursively. testspec must be a child directory of the directory named by the global ^UnitTestRoot. ^UnitTestRoot must specify a valid directory because RunTest checks for its existence before running tests. If testspec is not specified, then the ^UnitTestRoot directory is used. Any subdirectory whose name begins with an underscore ( _ ) is skipped.
testcase is a class that extends %UnitTest.TestCase (contains tests) in the form package.class and is an optional argument.
testmethod is a method name and is an optional argument.
testspec can also be an array of testsuite, or if you pass in a global name the global is an array of testsuites. In addition it also supports a comma separated set of values.
- qualifiers
- Any of the following command-line arguments can be combined as a single string, such as /noload/norecursive. All are optional.
The first four (debug, load, run, and recursive) are negatable Booleans. They can be turned on with /arg or off by adding no in the front, as /noload or adding =0 to the end, as /load=0.
/debug: Run in debug mode, which causes a break if a test fails. Default is /nodebug.
/load: Load use cases from the specified testspec. Default is /load. If /load and /run are both on, then all loaded classes, routines, and CSP files are deleted after the tests are run. To prevent them from being deleted at the end, load them with DebugLoadTestSuite and run them with DebugRunTestCase.
/run: Run the test suite. Use /norun if you only want to load, but not run, a suite into a namespace. Default is /run.
/recursive: Recurse the specified directory when loading test classes. Default is /recursive.
/display=all: Display extended information when loading exported test class definitions. /display=none displays limited information. Default is /display=all.
/autoload: Automatically load sub-directories with the given name when loading test classes. Default is /autoload=_autoload. When this qualifier is set, classes are loaded from the given sub-directory of the current directory and its ancestors. This makes it possible to use a class in multiple test suites without copying it to each of their directories.
/nodelete: Do not delete loaded classes when the test is complete.
- userparam
- An arbitrary argument passed in by the caller of the UnitTest. The top node of this variable becomes the value for the UserParam property of the Manager. The first level subscripts and their values are used to populate the UserFields array.
Example of RunTest:
set ^UnitTestRoot = "c:\test" do ##class(%UnitTest.Manager).RunTest("sql\sqlprocs") do ##class(%UnitTest.Manager).RunTest("sql\sqlprocs","/debug/recursive=0")Note: If any of your code needs to run in the %SYS namespace, zn to the %SYS namespace, run the code, then return to another namespace.
|
Optional - Specifies a comment line |
|
Optional - Specifies that the
|
|
The directory path of the UnitTest to run, or a path prefix (e.g. SQL\SQLStats) to run all UnitTests within this directory and all sub-directories |
- globalName
-
A optional global name, when specified, will be populated with each
- : utPath
from the given fileName, which is then passed as the 1st parameter to the- : RunTest(testspec,...)
method for execution. If specified, the value passed to the globalName parameters must have the following format:INPUT: "^utGlobal" // Where ^utGlobal is a valid IRIS Global Name OUTPUT: ^utGloba( - : utPath
)="" // e.g. ^utGlobal("SQL\dynamicSQL")="" ^utGlobal("Classes")="" - fileName
- A file path and name, which contains lines of tests in the following format, as specified above: [
- : #
|- : //
][- : -
]- : utPath
- qualifiers
- Any of the following command-line arguments can be combined as a single string, such as /noload/norecursive. All are optional.
The first four (debug, load, run, and recursive) are negatable Booleans. They can be turned on with /arg or off by adding no in the front, as /noload or adding =0 to the end, as /load=0.
/debug: Run in debug mode, which causes a break if a test fails. Default is /nodebug.
/load: Load use cases from the specified testspec. Default is /load. If /load and /run are both on, then all loaded classes, routines, and CSP files are deleted after the tests are run. To prevent them from being deleted at the end, load them with DebugLoadTestSuite and run them with DebugRunTestCase.
/run: Run the test suite. Use /norun if you only want to load, but not run, a suite into a namespace. Default is /run.
/recursive: Recurse the specified directory when loading test classes. Default is /recursive.
/display=all: Display extended information when loading exported test class definitions. /display=none displays limited information. Default is /display=all.
/autoload: Automatically load sub-directories with the given name when loading test classes. Default is /autoload=_autoload. When this qualifier is set, classes are loaded from the given sub-directory of the current directory and its ancestors. This makes it possible to use a class in multiple test suites without copying it to each of their directories.
/nodelete: Do not delete loaded classes when the test is complete.
- userparam
- An arbitrary argument passed in by the caller of the UnitTest. The top node of this variable becomes the value for the UserParam property of the Manager. The first level subscripts and their values are used to populate the UserFields array.
------------------------------------------------------------------------------ METHOD: addToExcludeGlobal DESCRIPTION: This method adds the given 'excludeUTPath' to the exclusion global: ^||UnitTest.exclude(0,...) // Master Map ^||UnitTest.exclude("x",$$$UPPER(excludeUTPath)) // Index Map INVOCATION: This method can be invoked in the following ways: ObjectScript: ##class(%UnitTest.Manager).addToExcludeGlobal(...) ..addToExcludeGlobal(...) SQL: N/A PARAMETERS: excludeUTPath - The directory path of the UnitTest to exclude from running, or a path prefix (e.g. SQL\SQLStats) to exclude all UnitTests within this directory and all sub-directories from running RETURN Value: The status of this method's invocation; Otherwise, return an error message if an error occurred ------------------------------------------------------------------------------
------------------------------------------------------------------------------ METHOD: deleteLoadedClasses DESCRIPTION: This method deletes all of the classes provided in the following parameter arrays: - classLoaded() - autoloadArray() - utLoadedArray() INVOCATION: This method can be invoked in the following ways: ObjectScript: ..deleteLoadedClasses(...) SQL: N/A PARAMETERS: classLoaded - A Pass By Reference array of classes that have been loaded into the namespace by the invocation of a given UnitTest autoloadArray - A Pass By Reference array of classes that have been auto-loaded into the namespace by the invocation of a given UnitTest utLoadedArray - A Pass By Reference array of classes that have been loaded into the namespace by the UnitTest during its invocation RETURN Value: The status from the invocation of this method ------------------------------------------------------------------------------
Inherited Members
Inherited Methods
- %AddToSaveSet()
- %ClassIsLatestVersion()
- %ClassName()
- %ConstructClone()
- %DispatchClassMethod()
- %DispatchGetModified()
- %DispatchGetProperty()
- %DispatchMethod()
- %DispatchSetModified()
- %DispatchSetMultidimProperty()
- %DispatchSetProperty()
- %Extends()
- %GetParameter()
- %IsA()
- %IsModified()
- %New()
- %NormalizeObject()
- %ObjectModified()
- %OriginalNamespace()
- %PackageName()
- %RemoveFromSaveSet()
- %SerializeObject()
- %SetModified()
- %ValidateObject()