nerdexam
Google

PROFESSIONAL-CLOUD-DEVELOPER · Question #214

You are planning to add unit tests to your application. You need to be able to assert that published Pub/Sub messages are processed by your subscriber in order. You want the unit tests to be…

The correct answer is D. Use the Pub/Sub emulator. The Pub/Sub emulator is a local emulation of the Google Cloud Pub/Sub service that runs on your development machine. It is free (no API charges), fully deterministic, and supports the same ordering semantics as the real service - making it ideal for reliable, repeatable unit…

Implementing and testing applications

Question

You are planning to add unit tests to your application. You need to be able to assert that published Pub/Sub messages are processed by your subscriber in order. You want the unit tests to be cost-effective and reliable. What should you do?

Options

  • AImplement a mocking framework.
  • BCreate a topic and subscription for each tester.
  • CAdd a filter by tester to the subscription.
  • DUse the Pub/Sub emulator.

How the community answered

(31 responses)
  • A
    16% (5)
  • B
    3% (1)
  • C
    6% (2)
  • D
    74% (23)

Explanation

The Pub/Sub emulator is a local emulation of the Google Cloud Pub/Sub service that runs on your development machine. It is free (no API charges), fully deterministic, and supports the same ordering semantics as the real service - making it ideal for reliable, repeatable unit tests. Option A (mocking framework) can simulate Pub/Sub behavior but cannot guarantee the same ordering logic as the actual service, reducing test fidelity. Options B and C use the real Pub/Sub service, which incurs costs, introduces network latency and non-determinism, and makes tests dependent on external infrastructure - all of which violate the cost-effective and reliable requirements.

Topics

#Pub/Sub#Unit Testing#GCP Emulators#Message Ordering

Community Discussion

No community discussion yet for this question.

Full PROFESSIONAL-CLOUD-DEVELOPER Practice