Skip to main content
Skip table of contents

Testing models

The following information describes how to create a unit test and run it to test the functionality of your model.

Creating a unit test

Use the unit test tools in NexJ Studio to verify the correctness of individual units of the model's design. You can run unit tests periodically to ensure that your model continues to behave as expected as you implement design changes.

Example unit test case

For example, you can create a unit test case to validate the behavior of the fullName attribute across the classes that contain it:

  1. Navigate to the Business Model layer in NexJ Studio and click the Unit Tests tab.
  2. Right-click in the navigator and select New Unit Test.
  3. In the Name field, enter Telcom and click Finish. The new Telcom unit test opens in the editor and displays the Test Cases tab.
  4. In the Overview tab, enter the following Description: Unit tests for the training:Telcom model.
  5. In the Test Cases tab, click the Add button
    to add a new test case.
    A single unit test can contain multiple separate test cases that run in the order that they appear in the Test Cases list.
  6. Double-click the name of the new test case to edit it and change it to fullNameTest.
  7. Double-click the Description area for the test case and enter: Tests the fullName attribute on all the classes that contain it.
  8. In the test case script area (the large blank area at the bottom), enter the following Scheme script:

    SCHEME
    (define c (training:Company'new (: lastName "YourCo") (: businessNumber "BN-1234") (: incorporationDate #m1999-11-15)))
    (define p (training:Person'new (: firstName "Bob") (: initials "A") (: lastName "Sled") (: company c) (: primaryLanguage (training:LanguageEnum'get'ENGLISH))))
    (define tp (training:TelcomType'new (: name "Business")))
    (define email (training:EmailAddress'new (: entity p) (: type tp) (: name (tp'name)) (: address "bsled@yourco.com") (: displayName "Bob Sled")))
    (define tel (training:TelephoneNumber'new (: type tp) (: name (tp'name)) (: address "(416) 555-1212") (: entity p) (: extension "x123")))
    (commit)
    
    (assert-equal "Company: YourCo (Business Number: BN-1234, Since: 1999)" (c'fullName))
    (assert-equal "Person: Sled, Bob - Company: YourCo (Business Number: BN-1234, Since: 1999)" (p'fullName))
    (assert-equal "Email: Business-bsled@yourco.com (Bob Sled)" (email'fullName))
    (assert-equal "Phone: Business-(416) 555-1212 x123" (tel'fullName))

    The script defines related instances of the training:Company, training:Person, training:EmailAddress, and training:TelephoneNumber classes, commits them to the database, and then uses (assert-equal) to verify the calculated fullName attribute values.

  9. Save your changes.

Running the unit test

You must ensure that NexJ Studio is configured to run the unit test using the correct environment.

You want the unit test to run in the UnitTest environment that was created when you created your model:

  1. Open the Project menu in NexJ Studio and select Properties.
  2. Select Deployment in the list at the left.
  3. Set the Unit Test Server property to UnitTest (environment,test).
  4. Click OK.

To run the unit test:

  • In the Unit Tests tab in NexJ Studio, right-click the training:Telcom unit test and select Run Unit Test.

When the unit test runs, the following actions take place:

  1. The unit test database is recreated.
  2. The steps of each of the test cases are carried out.
  3. The results are reported in the Unit Test view (located in a tab beside the model tab).

NexJ Studio does not validate the names of test cases. If you have a unit test case with an invalid name, it will be reported as not found when you run your unit tests.

The Unit Test view contains a summary of the test cases that ran, and whether they succeeded or failed. Test cases that complete correctly are marked with a checkmark, test cases that fail are marked with an x.

Successful unit test

Failed unit test


The test case that you created in this example verifies four values. If even one of them is a mismatch, the entire test case is marked as having failed. To find out exactly where the test case failed, click the name of the failed test case. The details of the failed test case display in the lower part of the view.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.