Skip to main content

Example: Creating and Exporting a Test Class

The class MyPackage.TestMe contains a method named Add that adds two integers. In this example you create and run a unit test to check that the Add method correctly adds two integers.

Create a test class that will contain the unit tests. Here's how:

  1. Use Atelier to create a new class named Tests in the MyPackage package. Tests must extend %UnitTest.TestCase.

  2. Add the following method named TestAdd and compile Tests:

    Method TestAdd()
     do $$$AssertEquals(##class(MyPackage.TestMe).Add(2,2),4, "Test Add(2,2)=4")
     do $$$AssertNotEquals(##class(MyPackage.TestMe).Add(2,2),5,"Test Add(2,2)'=5")
  3. Export the class Tests to an XML file in your unit test directory. If you have not yet created a test directory please create one. This example uses C:\unittests\mytests\.

    1. In Atelier, click File > Export.

    2. Under Atelier Export , click Legacy XML File. Click Next

    3. Select your project, Test.cls, and the c:\unittests\mytests\ directory.

    4. Click Finish.

    5. Atelier exports the test class to C:\unittests\mytests\cls\MyPackage.


Note that the directory name, in this case mytests, is the name for a suite of tests and is also a child of the directory specified by ^UnitTestRoot. Running Manager.RunTest(“mytests”) runs all of the tests stored in the mytests directory.


You can also export the test classes as .cls files rather than XML files. Instead of exporting them, you can also simply copy them from your Atelier workspace.