Skip to main content

Example: Executing a Test

Now execute the unit test using %UnitTest.Manager.RunTest. Here's how:

  1. 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 ZN to change namespaces.

  2. Set the value of the ^UnitTestRoot global to the parent of the directory containing your exported test class.

    USER>Set ^UnitTestRoot="c:\unittests"
    
    
  3. Execute the test using the method %UnitTest.Manager.RunTest.

    USER>do ##class(%UnitTest.Manager).RunTest("mytests")
    
  4. Caché loads the test class from the XML file, compiles the class, executes the test, and delivers a report to the terminal.

    
    ===============================================================================
    Directory: C:\unittests\mytests\
    ===============================================================================
    mytests begins ...
    Load of directory started on 09/29/2014 14:36:57 '*.xml;*.XML'
    
    Loading file C:\unittests\mytests\Test.xml as xml
    Imported class: MyPackage.Tests
    
    Compilation started on 09/29/2014 14:36:57 with qualifiers ''
    Compiling class MyPackage.Tests
    Compiling routine MyPackage.Tests.1
    Compilation finished successfully in 0.026s.
    
    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: .006455 sec.
        TestAdd passed
      MyPackage.Tests passed
    mytests passed
    
    
  5. The last line shows the URL for the CSP test report.

Note:

Running Tests in this fashion deletes them from Caché after they execute. If you return to studio to view Tests after executing the test, you will see a dialog box warning that Tests has been deleted from the server. The dialog box asks whether you want to close the file. Click No. You can then still save and recompile the test class.

For explicit instructions on using ZN to change namespaces, read the Changing Namespaces subsection of the Introduction to the Terminal section of Using the Terminal.

FeedbackOpens in a new tab