Example: Executing a Test
Now execute the unit test using %UnitTest.Manager.RunTest. Here's how:
Open the Terminal in the namespace that contains your unit tests; in this example USER. If the Terminal does not open in the correct namespace, use set $namespace = "USER" to change namespaces.
Set the value of the ^UnitTestRoot global to the parent of the directory containing your test class file.
Execute the test using the method %UnitTest.Manager.RunTest.
InterSystems IRIS loads the test class from the test file, compiles the class, executes the test, deletes the test code from the server, and delivers a report to the terminal.
=============================================================================== Directory: C:\unittests\mytests\cls\MyPackage\ =============================================================================== mytests\cls\MyPackage begins ... Load of directory started on 07/05/2022 11:09:35 '*.xml;*.XML;*.cls;*.mac;*.int;*.inc;*.CLS;*.MAC;*.INT;*.INC' Loading file C:\unittests\mytests\cls\MyPackage\MyPackage.Tests.cls as udl Compilation started on 07/05/2022 11:09:35 Compiling class MyPackage.Tests Compiling routine MyPackage.Tests.1 Compilation finished successfully in 0.672s. Load finished successfully. MyPackage.Tests begins ... TestAdd() begins ... AssertEquals:Test Add(2,2)=4 (passed) AssertNotEquals:Test Add(2,2)'=5 (passed) LogMessage:Duration of execution: .000356 sec. TestAdd passed MyPackage.Tests passed mytests/cls/MyPackage passed Use the following URL to view the result: http://172.30.160.1:52797/csp/sys/%25UnitTest.Portal.Indices.cls?Index=3&$NAMESPACE=USER All PASSED
The last line shows the URL for the test report.
Running Tests in this fashion deletes them from InterSystems IRIS after they execute. If you return to VS Code to view Tests after executing the test, you will see that the file is not synchronized with the server. You can save or recompile the class to add the code back to the server.
If you do not want to delete your classes, you must supply the “/nodelete” qualifier to RunTest.