KNOWLEDGE / 03
Automation architecture
Test framework structure, layer boundaries, maintainability, and reliable quality signals.
Questions and practice
Open a question to see the answer, examples, and exercises.
What should be automated first?Junior
Answer
Stable, repeatable, high-risk scenarios with a reliable oracle and acceptable maintenance cost.
Examples
- A critical checkout with a clear API outcome is usually a better candidate than a changing visual prototype.
Practice exercises
- Compare two scenarios by risk, repeatability, oracle quality, and maintenance cost.
Why use the test pyramid if it is not a strict formula?Junior
Answer
The test pyramid encourages most checks to live at fast, local levels while expensive end-to-end scenarios cover risks that cannot be addressed below. Its shape depends on the product architecture; the goal is fast feedback, useful diagnostics, and sustainable maintenance rather than a prescribed test count per layer.
Examples
- A calculation rule is covered by unit tests, an integration contract by API tests, and one critical journey through the UI.
Practice exercises
- Place ten checks for a familiar feature across test levels and justify the most expensive end-to-end cases.
Why does a fixed sleep make automation unstable?Junior
Answer
A fixed delay does not know when the system is actually ready: a short sleep causes flaky failures, while a long one slows the suite. Wait for an observable condition with a bounded timeout—an API response, element state, completed job, or emitted event—and preserve diagnostics when the timeout expires.
Examples
- Instead of sleep(5000), the test waits until the operation status becomes Completed, for at most ten seconds.
Practice exercises
- Find three fixed sleeps in a test scenario and replace each with a specific readiness condition.
What is a flaky test?Middle
Answer
A test with unstable outcomes under materially identical conditions; the cause may be in the test, environment, or product.
Examples
- A test sometimes fails because of a request race even though code and test data did not change.
Practice exercises
- For an unstable test, plan the evidence to collect before adding a retry.
How do fixtures help isolate automated tests?Middle
Answer
A fixture prepares controlled state, provides a resource to the test, and performs cleanup. A good fixture has explicit scope, creates minimal data, does not hide important preconditions, and is safe under parallel execution. Shared mutable state creates order dependence and failures that are difficult to reproduce.
Examples
- Each test creates a user in a unique namespace through the API and deletes it afterwards, even when an assertion fails.
Practice exercises
- Design a fixture for parallel order tests, including setup, uniqueness, cleanup, and partial-failure behaviour.
When is service virtualization more useful than a real dependency?Middle
Answer
A virtual service provides controlled responses, failures, latency, and rare sequences without depending on an external system’s availability. It speeds feedback and makes negative scenarios reproducible. It does not prove real compatibility, so combine it with contract tests and selected integration checks.
Examples
- A payment-provider stub returns a timeout, duplicate callback, and success in sequence to test retry logic.
Practice exercises
- Choose one unstable integration and define what to simulate and what must remain a real-environment test.
Why separate test logic from client and page layers?Senior
Answer
So scenarios describe behaviour while protocol and UI details change locally.
Examples
- An API endpoint change should require updating the client, not every business scenario.
Practice exercises
- Design a checkout flow—API setup, UI action, API assertion, cleanup—and mark the layer boundaries.
What problem does contract testing solve between services?Senior
Answer
Contract testing checks that providers and consumers agree on requests, responses, and compatible changes at service boundaries. A consumer-driven approach captures behaviour that clients actually need, while schema validation checks message shape. Contracts do not verify complete business flows, production configuration, or every data semantic.
Examples
- A consumer expects a currency field and specific 404 behaviour; provider verification runs those expectations before release.
Practice exercises
- For two services, define the contract, ownership, versioning rules, and one scenario that still needs an end-to-end test.
What does a test architecture need for safe parallel execution?Senior
Answer
Parallelism requires isolated data and resources, controlled concurrency, independent tests, and correlation identifiers. Logs, traces, screenshots, and network artefacts must map to a specific worker and test run. Otherwise, speed merely creates race conditions, noise, and failures that cannot be diagnosed.
Examples
- Each worker receives a separate tenant and correlation ID, while the report gathers every request and event for one test.
Practice exercises
- Plan a suite migration from one to eight workers, covering resources, limits, isolation, and failure evidence.