Unit Tests

The Unit Tests feature allows you to test Integration Server services hosted on Cloud.

Overview

Unit Tests feature lets you test Integration Server services hosted on Cloud. A test suite is one or more test cases grouped together. Each test case defines a service to be tested, the type of test to be performed, and provides a user interface to define input data and expected output data. When the service execution is completed, the output is validated against the expected output defined in the test case.

The Unit Test component is not available for Universal Messaging only solution.

The following figure depicts the unit test structure in a solution.

Actors

  • Integration developers who develop and expose the integrations over HTTPS in IBM® webMethods Cloud Container.
  • Integration executors who runs integrations.

Before you begin

  • You must have a fully functional Integration Server product instance that contain services and related files.
  • You must have the permissions to create and delete unit tests in IBM webMethods Cloud Container under Settings > Access Profiles > Administrative Permissions > Functional Controls > Unit Tests.

Basic Flow

  1. Log in to IBM webMethods Cloud Container.
  2. From the IBM webMethods Cloud Container navigation bar, click Solutions > Solution List. The Solution List page appears.
  3. From the Solution List page, click any existing solution. The Solution Explorer page appears.
  4. Select Unit Tests.

Creating a Test Suite

In this tutorial, we will see how to create a test suite for public services of the Integration Server and then execute the test case and test suite. To achieve this, follow the instructions given below:

  1. Go to Unit Tests screen.

  2. Click Add test suite.

    A New Test Suite screen will appear where you will be prompted to provide the following details:

    • Name: Provide a unique name, say Public_services for the new test suite.
    • Description: Provide a description for the new test suite.
    • Runtime instance: Select a runtime instance.
    • Click Save.

    This creates the new test suite (Public_services). You will be redirected to the test suite editor.

Creating a Test Case

After you create a test suite, let's see how to create a test case.

  1. On the test suite editor, select the newly created (public_services) test suite.

  2. Click Add test case.

    A new test case editor appears. Provide the following details:

    • Test Case Details: Provide the test case name.
    • Description: Add the description for the test case.
    • Service asset: Enter the qualified name of the service or click Select Service.

    For example, pub.math:addInts.

    The screen loads Input and Expected output details as shown below:

    • Input: Provide the required input details, so that whenever this service is invoked for addInts, it will take the input provided here.

    • Include empty values for string types: If you do not provide an input value for a string field, the value will be null by default. If you select this option, the empty value will be considered. If this option is unchecked, then during the service execution, the value for the empty field will be derived from a global variable, if defined.

    • Expected output: By default, the values of all fields of the expected output will be asserted with the actual values of the service run. If you want certain fields to be asserted, then select the check boxes for these fields. In the Expected output panel, complete the following details:

      Field Description
      Assertion type Select the Assertion type depending on your requirement.
      Pipeline Allows you to assert output data returned by the service for the provided input. The output that the service is expected to return.
      Exception Allows you to assert service exception thrown by the service. You can either assert an exception class name by providing a value in the Exception class name, or assert an error message by specifying the error message in the Error message field. You can provide values for both the fields in which case both of them will be asserted when a test case runs.

      The screen loads Input and Expected output details as shown below:

    • Load Data: Click this option to load existing input or output data captured from Integration Server or Designer.

    • Mocks: Mocks are used when other services that a service may require to properly execute may not be available when a test case or test suite is developed or executed. Mocks provide a means of simulating execution of such services that are unavailable. Service mocking functionality is supported in Unit Tests only if the solution has Integration Server 10.3 with Fix 10 and above, or Integration Server 10.5 with Fix 4 and above.
      Field Description
      Add Mock In the New mock page, enter the qualified name of the service in the Service to mock field or click Select Service to add the list of services to mock.
      Mock details  
      Action type Following are the valid selections:
        Send fixed response: Intercepts the service and returns the data specified in Output. For example,
        Call another service: Intercepts the service and use another service and send its response as response of the mocked service. For example,
        Throw Exception: Intercepts the service and returns an exception with specific message. For example, whenever an addInts service is invoked, throw an exception with this message.
    • Click Add.

      The defined mocks will be added to the test case. Similarly you can have multiple defined mocks for executing the test case.

    • After adding the expected output, click Save. This will create the test case addIntsCase1 in the test suite public_services.

    Deactivate and Delete a defined mock

    To deactivate a particular defined mock, hover the cursor on the service name, select the check box next to the service and select Deactivate.

    To delete a particular defined mock, hover the cursor on the service name, and select the check box next to each service and select Delete.

Executing Test Cases

To run the test case created, click the Run Once option in the editor.

A list of success and failure messages appear on the Test case result window. For the above test case the result is success, so the success message appears as shown below.

When a test case encounters an error, the error reports appear in a stack trace which contains a sequence of stack trace elements which can be useful for debugging purposes.

Executing Single Test Suite

Let's say, you want to execute a single test suite with multiple test cases in it. To do this, follow the steps given below:

  1. Open the test suite list.

  2. Click Run once.

  3. To run specific test cases inside the test suite, select test cases from the list, and then click Run once option above the test cases list. The execution is considered to be successful if all the test cases in the test suite is successfully executed.

Executing Multiple Test Suites

To execute multiple test suites, follow the steps given below:

  1. Select the Name check box to select all test suites.

  2. Click the Run once option to execute the test suites.

    This executes all test suites.

    You may use the icon, to view the last run results of the test suites or test cases.

Displaying the API Details of a Test Suite

Navigate to API Details option to view the API details of the test suite such as the HTTP Method, URL, and the parameters that are required to invoke this test suite from an external system, for example, Postman.

In the API Details window, copy the API endpoint.

Now, append the same details to execute the test suite from the external system.

Viewing Test Suites Execution Results

To view the list of test suites that were executed in the solution along with the status, click Test results view.