Prepare and test your skills

Prepare and test your skills

Free sample question with answers and detailed explanation below. The Professional Cloud Developer practice bank has an additional 608 practice questions.Try 10 free realistic questions: instant score, no credit card, and no account required.
You are developing a Python microservice for Cloud Run that validates incoming Pub/Sub order messages against a data schema defined in a separate internal repository and archives valid payloads to Cloud Storage. When you prompt Gemini Code Assist in your IDE with "write tests for my service", the generated output contains several defects:
Which prompt engineering and context-management approach should you use to generate a relevant, executable pytest unit test suite for the process_order_event function?
"pytest unit test Pub/Sub Cloud Storage" in the chat panel while excluding import statements and schema references so the assistant relies on its general training data rather than project-specific constraints.Treating an AI coding assistant chat panel like a web search engine—by entering brief keyword fragments and stripping out project imports or schema references—forces the large language model to rely purely on generic public code patterns from its pre-training dataset.
process_order_event actually accepts, validates, or returns, leading to generic boilerplate instead of executable tests.import statements prevents Gemini Code Assist from seeing which exact versions or client libraries (such as google-cloud-storage or google-cloud-pubsub) need to be patched.Pub/Sub and Cloud Storage as keywords does not instruct the assistant to replace external cloud calls with unit test mocks.You were only looking for a generic, conceptual example of how pytest works with Google Cloud SDKs in a greenfield tutorial rather than generating runnable unit tests for an existing microservice.
Dumping massive volumes of raw debug logs and full commit history into a single unstructured prompt attempts to leverage large context windows instead of supplying targeted, structured context such as function signatures and schemas.
pytest and a clear test structure leaves the assistant guessing whether to generate unittest.TestCase classes, pytest functions, or pseudocode.You were diagnosing an active production failure by providing a concise, filtered error log snippet alongside the failing function; however, for unit test generation, clean function signatures, imports, and explicit schema references are far more effective than raw commit histories.
process_order_event with its import statements visible, highlight the function, use @ in Gemini Code Assist chat to reference the internal schema repository, and write a focused prompt specifying pytest, mocked Cloud Storage and Pub/Sub dependencies, required edge cases, and expected test structure.Contextual prompt engineering combines explicit natural language instructions with active IDE workspace signals and indexed repository references so an AI coding assistant generates accurate, project-specific code. Rather than guessing types or APIs from general pre-training data, Gemini Code Assist grounds its generation in the exact function signatures, import statements, and private schemas active in your development environment.
import statements present and highlighting process_order_event supplies the exact method signature, type hints, and library dependencies directly into the assistant's context window.@ symbol in Gemini Code Assist chat attaches remote repository context from the separate internal schema repository, ensuring generated test payloads use real field names and data types.pytest along with mocked Cloud Storage and Pub/Sub clients guides the model to isolate the unit under test rather than invoking live network endpoints.import statements improve symbol resolution and parameter matching.@ brings private microservices, libraries, and data models into scope.pytest and mocking patterns yields ready-to-run test files that fit existing CI pipelines.Generic prompts leave the assistant to infer frameworks, dependencies, and data contracts. Supplying curated local code, cross-repo schema context, and clear mocking and edge-case constraints produces an executable, isolated unit test suite with minimal manual rework.
process_order_event, generate docstrings, infer missing schema fields, and produce both unit and integration test suites simultaneously without opening the source file.Combining refactoring, documentation generation, schema inference, and multi-tier test creation into a single chat prompt forces the AI assistant to perform multiple distinct cognitive tasks in one pass while operating without local file context.
import statements, local type annotations, and the exact implementation of process_order_event.Nowhere is a single massive prompt optimal for complex code generation; however, breaking those goals into separate, sequential prompts—first refactoring with the file open, then generating docstrings, and finally generating unit tests with @ repository context—would follow effective prompt engineering practices.
Answer them yourself and get your score the moment you finish. No account needed.
Full access includes
Keep the momentum going with these hand-picked practice scenarios
Last updated Validated