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?
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?
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.
The answer is D. See https://cloud.google.com/pubsub/docs/emulator, "Testing apps locally with the emulator".
Agree with D, use the emulator for testing.
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.
B is the answer.
option B
https://brightsec.com/blog/unit-testing-best-practices/ One scenario per test
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.
D is correct.