Google Professional Cloud Developer Question 281
Single answerGoogle Cloud PlatformYou are developing a serverless application using Google Cloud Functions. The application uses Firestore as the database. To perform integration tests without incurring costs or affecting production data, you want to simulate the Firestore database in your test environment. Which approach should you take?
- A
Use the Firestore Emulator to simulate a local Firestore environment for integration testing.
- B
Deploy a separate Firestore instance in a development project and use it for testing.
- C
Mock the Firestore API calls in your test code instead of using an emulator.
- D
Perform integration tests directly on the production Firestore database.
Show answer and explanation
Correct answer: A
Explanation
The Firestore Emulator is specifically designed for testing purposes, allowing developers to simulate Firestore behavior locally. It avoids costs and ensures production data is not impacted, making it the best choice for integration testing in this scenario.
- A. Correct.
This is the correct approach. The Firestore Emulator allows you to simulate Firestore locally in a test environment without incurring costs or affecting production data, making it ideal for integration tests.
- B. Incorrect.
While creating a separate Firestore instance in a development project keeps production data safe, it still incurs costs and is less efficient compared to using the Firestore Emulator for local testing.
- C. Incorrect.
Mocking Firestore API calls is suitable for unit tests but does not provide the full end-to-end testing capabilities required for integration tests, as it doesn't simulate Firestore behavior accurately.
- D. Incorrect.
Running tests directly on the production Firestore database is highly discouraged because it risks corrupting production data and incurs unnecessary costs.