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
-
Select the test case that you created during the previous step.
-
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.
Creating a Topic Receiver Test Case
-
Create a new test case.
-
Name it Receive Test Case.
-
Add the Receive MQTT Message test step to this test case.
-
Open the test step.
-
Click the Connection drop-down list and select SampleConnection.
-
Enter
sampletopic/samplemessage
to the list of subscribed topics.
Starting the Test
-
Switch to the test suite editor and click to run both test cases in parallel.
-
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.
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.