I'm new to test automation and Google Pub/Sub. I'm developing automation scripts for regression testing. My automation framework is built with Java, Maven, Cucumber and TestNG

My application is a spring batch job. It consumes an input file and after processing the data, corresponding messages are published to a topic.

How do I automate the testing of publishing message to a topic functionality? I wanted to test if the right messages are published to the topic.

Kindly provide me some approach to automate testing of Pub/Sub functionality.

1 Answer 1


Although the question is highly broad ("How to test"-ish) I would guess that a good first step would be to create automated checks in two aspects:

1 - (Main part) Consumer Contracts

You may want to check if your application is generating messages in the format expected by your consumer application(s).

In case you are not familiar, here and here you can find an overview of consumer-driven contract checking using Pact.

Specifically for async messaging, you can find some information here.

Alternatively to Pact, you may want to use Spring Cloud Contract.

2 - (Complementary) E2E checks

You may want to complement the contract checks with checks that will boot up your Spring service completely and assert against the behavior of all its components. More information here.

  • Thank you for your explanation and pointers. Those were really helpful to understand. Since we do not have a consumer contract yet, I will be only testing the generation of messages in topic. For this, I've drafted out an approach to create a pull subscription to our topic for test. Then will receive the messages from subscriber in test script and validate the expected result.
    – Hima
    Dec 18, 2020 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.