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…
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)- A16% (5)
- B3% (1)
- C6% (2)
- D74% (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
Community Discussion
No community discussion yet for this question.