Professional Cloud Developer Exam QuestionsBrowse all questions from this exam

Professional Cloud Developer Exam - Question 197


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?

Show Answer
Correct Answer: D

Using the Pub/Sub emulator is a cost-effective and reliable solution because it allows you to test your application's Pub/Sub functionality locally without incurring any real costs. The emulator mimics the behavior of the actual service, ensuring that messages are processed in the correct order for your unit tests. This approach is more efficient and manageable than creating multiple topics and subscriptions or adding filters, which can introduce complexity and additional costs.

Discussion

8 comments
Sign in to comment
x_cathOption: D
Dec 15, 2022

The answer is D. See https://cloud.google.com/pubsub/docs/emulator, "Testing apps locally with the emulator".

micoamsOption: D
Dec 19, 2022

Agree with D, use the emulator for testing.

omermahgoubOption: D
Jan 28, 2023

Option B, creating a topic and subscription for each tester, would be costly and time-consuming as it would require creating and managing a large number of topics and subscriptions. Additionally, it would not ensure that messages are processed in order, as messages may be delivered out of order to different subscriptions. Option D, using the Pub/Sub emulator, would be cost-effective and reliable as it allows you to test your application's Pub/Sub functionality locally without incurring any costs. Additionally, the emulator allows you to easily assert that messages are processed in order by using the same topic and subscription for all unit tests.

zellckOption: B
Dec 13, 2022

B is the answer.

sharath25Option: B
Dec 14, 2022

option B

TNT87Option: B
Dec 20, 2022

https://brightsec.com/blog/unit-testing-best-practices/ One scenario per test

telpOption: D
Jan 11, 2023

Agree with D. They want unit test cost-effective and reliable so need an emulator which will never have an issue to do that. B is not correct for me because the unit test using a real topic and subscription can have issue sometimes and it's not cost-effective to pay for each tester a subscription. The b is more a solution for integration test.

RajanOption: D
Sep 23, 2023

D is correct.