Test MQTT communication

Relevant for: API testing

This topic explains how to add MQTT activities to your API test.

Overview

Use OpenText Functional Testing's native API testing capabilities to test your application that communicates and exchanges data using MQTT.

MQTT activities allow OpenText Functional Testing to connect to an MQTT broker, subscribe or publish to a topic, receive messages on a topic, and disconnect from the MQTT broker. MQTT activities are available in the Toolbox pane under the MQTT node.

In the testing process, OpenText Functional Testing serves as a client to test the connection with an MQTT broker and the core Subscribe/Publish model of MQTT communication.

Back to top

Connect to an MQTT broker

Before you test, you must configure the host name and port in the Connect to MQTT Broker activity to connect to an MQTT broker.

This is mandatory for testing the Subscription/Publication of messages as the broker serves as a hub for receiving messages published by clients and distributing them to subscribed clients.

To connect to an MQTT broker:

  1. Create an API test or open an existing API test, and expand MQTT activities under the MQTT node in the Toolbox pane.
  2. Add a Connect to MQTT Broker activity to the Test Flow in the canvas.
  3. In the Input/Checkpoints tab of the Properties pane, set the properties of the activity.

    • Host Name: Enter the IP address or host name of your MQTT broker.
    • Port: Enter the network port to connect to the broker. Accept the default (1883) or enter a different port number.

Back to top

Subscribe to a topic

After you have connected to an MQTT broker, you can add Subscribe to Topic activities to your test. This enables your client to receive any messages on the topic published by other clients.

To subscribe to a topic:

  1. In the Toolbox pane, from the MQTT node, add a Subscribe to Topic activity to the Test Flow in the canvas.
  2. In the Input/Checkpoints tab of the Properties pane, in the Value cell for the MQTT Broker property, click the Link to data source button . The Select Link Source dialog box opens.

  3. In the list of available steps, select the Connect to MQTT Broker activity.
  4. In the right properties pane, select the MQTT Broker property and click OK to link the Connect to MQTT Broker step to the Subscribe to Topic step.
  5. Continue to set the parameters in the Input/Checkpoints tab of the Properties pane.

    Topic: You can set the parameter to a topic filter containing wildcards "+" or "#" or a topic name with no wildcards.

    A topic must contain at least 1 character and can consist of one or more topic levels. Each topic level is separated by a forward slash (/).

Back to top

Publish to a topic

After you have connected to an MQTT broker, you can add Publish to Topic activities to your test. This enables your client to publish messages on topics to the MQTT broker.

To publish to a topic:

  1. In the Toolbox pane, from the MQTT node, add a Publish to Topic activity to the Test Flow in the canvas.
  2. In the Input/Checkpoints tab of the Properties pane, in the Value cell for the MQTT Broker property, click the Link to data source button . The Select Link Source dialog box opens.
  3. In the list of available steps, select the Connect to MQTT Broker activity.
  4. In the right properties pane, select the MQTT Broker property and click OK to link the Connect to MQTT Broker step to the Publish to Topic step.
  5. Continue to set the parameters in the Input/Checkpoints tab of the Properties pane.

    For the naming convention of Topic, see Subscribe to a topic.

Back to top

Receive from a topic

After you have subscribed to a topic, you can add Receive from Topic activities to your test. This enables your client to successfully receive the messages on that topic through the MQTT broker.

To receive from a topic:

  1. In the Toolbox pane, from the MQTT node, add a Receive from Topic activity to the Test Flow in the canvas.
  2. In the Input/Checkpoints tab of the Properties pane, in the Value cell for the MQTT Broker property, click the Link to data source button . The Select Link Source dialog box opens.
  3. In the list of available steps, select the Connect to MQTT Broker activity.
  4. In the right properties pane, select the MQTT Broker property and click OK to link the Connect to MQTT Broker step to the Receive from Topic step.
  5. Continue to set the parameters in the Input/Checkpoints tab of the Properties pane.

    To successfully receive messages on topics, the topic must be the same as that you subscribed to.

Back to top

Disconnect from an MQTT Broker

To stop sending to or receiving messages from the MQTT broker, you can add a Disconnect from MQTT Broker activity to your test.

To disconnect from an MQTT broker

  1. In the Toolbox pane, from the MQTT node, add a Disconnect from MQTT Broker activity to the Test Flow in the canvas.
  2. In the Input/Checkpoints tab of the Properties pane, in the Value cell for the MQTT Broker property, click the Link to data source button . The Select Link Source dialog box opens.
  3. In the list of available steps, select the Connect to MQTT Broker activity.
  4. In the right properties pane, select the MQTT Broker property and click OK to link the Connect to MQTT Broker step to the Disconnect from MQTT Broker step.

Back to top

Run the test

After all necessary MQTT activity steps are added, click the Run button to run the test flow.

Back to top