2. Listening for MQTT Messages

Applies to ReadyAPI 3.53, last modified on June 07, 2024

When you publish a message to an MQTT broker, the broker forwards it to all clients subscribed to the topic. You can check if the broker you are testing does this.

To check if the broker functions appropriately, you can use a WebSocket-based solution to catch the messages, or you can handle them directly from ReadyAPI.

Configuring the Topic Publisher Test Case

  1. Select the test case that you created during the previous step.

  2. Important: Add the Delay test step to the beginning of the test case. This ensures that the receiver test case will be able to subscribe to the topic before the message is sent. For that, double-click the Delay test step and set the delay to 100.

    ReadyAPI: Adding the delay

Creating a Topic Receiver Test Case

  1. Create a new test case.

  2. Name it Receive Test Case.

  3. Add the Receive MQTT Message test step to this test case.

    ReadyAPI: The Receive MQTT Message button
  4. Open the test step.

  5. Click the Connection drop-down list and select SampleConnection.

  6. Enter sampletopic/samplemessage to the list of subscribed topics.

    ReadyAPI: Editing the list of subscribed topics

    Click the image to enlarge it.

Starting the Test

  1. Switch to the test suite editor and click to run both test cases in parallel.

    ReadyAPI: The Parallel test case run button
  2. Click to run the test suite.

ReadyAPI will run both test cases at the same time.

  • The receiver test case will start waiting for messages from the broker.

  • The topic publisher test case will first wait for the time period which you have specified in the Delay test step, and then publish the sample topic.

  • The broker will handle the topic and forward it to clients. The receiver test step will catch this message.

If the tested broker functions properly, you will see the message in the Received message text box.

ReadyAPI: The received MQTT message

Click the image to enlarge it.

Note: You can use assertions to automatically verify the message content matches to the results you expected.

On the next step, you will learn how to catch the Will messages the broker sends when connections to the client break.

Prev     Next

See Also

MQTT Testing Tutorial
About IoT MQTT Testing

Highlight search results