Google Professional Cloud Developer Question 280
Single answerGoogle Cloud PlatformYou are developing a serverless application on Google Cloud that uses Firestore as its database. To ensure the application works as expected, you decide to implement integration testing in your CI/CD pipeline. However, you want to avoid affecting live data during these tests. Which approach should you follow?
- A
Use the Firestore emulator to run integration tests locally or in the CI/CD pipeline.
- B
Run your integration tests directly against the live Firestore database configured in a separate test project.
- C
Mock the Firestore API using a custom script for your integration tests.
- D
Use the Cloud Functions emulator to simulate Firestore interactions for testing purposes.
Show answer and explanation
Correct answer: A
Explanation
Integration testing requires a setup that closely mimics real-world scenarios without impacting live environments. The Firestore emulator is specifically designed for this purpose, enabling developers to test Firestore-integrated applications safely and effectively. It is a recommended best practice to use emulators for integration testing, as they provide isolation, avoid live data modifications, and reduce costs.
- A. Correct.
This is the correct answer. The Firestore emulator provides a local environment to emulate Firestore behavior, allowing you to run integration tests without interacting with live data. It is designed specifically for such use cases.
- B. Incorrect.
Running tests against a live database, even in a separate test project, can still introduce risks such as unintended data modifications or higher costs. This approach is not recommended for integration testing.
- C. Incorrect.
While mocking the Firestore API might work for unit tests, it does not provide the same level of integration testing fidelity as using the Firestore emulator, which better simulates real-world interactions.
- D. Incorrect.
The Cloud Functions emulator is used to simulate Cloud Functions, not Firestore. It cannot replicate Firestore's behavior and is not suitable for Firestore integration testing.