Full-Stack Development Quality Control & Assurance 4 — Questions and Answers
Question 1: What does a 'spy' test double do differently from a 'stub'?
- Spies replace the real function; stubs do not
- Spies record calls and arguments while optionally delegating to the real implementation; stubs just return preset values (Correct answer)
- Stubs record calls; spies only replace return values
- There is no practical difference between spies and stubs
Correct answer: Spies record calls and arguments while optionally delegating to the real implementation; stubs just return preset values
A spy wraps the real function to record call metadata, whereas a stub replaces the function with a fixed-return implementation.
Question 2: In API testing, what does asserting the response schema validate?
- That the API returns data within an acceptable time
- That the response JSON structure and field types match the contract (Correct answer)
- That authentication tokens are correctly signed
- That the correct HTTP method was used
Correct answer: That the response JSON structure and field types match the contract
Schema validation checks that response fields, types, and required properties match the API contract, catching breaking changes early.
Question 3: Which testing pyramid level is the MOST expensive to write, run, and maintain?
- Unit tests
- Integration tests
- End-to-end (E2E) tests (Correct answer)
- Contract tests
Correct answer: End-to-end (E2E) tests
E2E tests run through the full application stack in a real browser or environment, making them slowest and most brittle to maintain.
Question 4: What is 'contract testing' used for in a microservices architecture?
- Verifying SLA uptime agreements with cloud vendors
- Ensuring provider services fulfill the API contracts that consumer services depend on (Correct answer)
- Testing network firewall rule contracts
- Validating software licensing terms automatically
Correct answer: Ensuring provider services fulfill the API contracts that consumer services depend on
Contract testing (e.g., using Pact) verifies that a service's API fulfills the expectations recorded by its consumers, enabling independent deployments.
Question 5: When should you use `expect.assertions(n)` in a Jest async test?
- To set the timeout for the async operation
- To ensure a specific number of assertions ran, catching cases where async callbacks were never called (Correct answer)
- To skip assertions if a condition is not met
- To run assertions in parallel for performance
Correct answer: To ensure a specific number of assertions ran, catching cases where async callbacks were never called
`expect.assertions(n)` prevents silent test passes when async callbacks are never invoked by requiring exactly n assertions to have been called.
Question 6: What is 'boundary value analysis' in software testing?
- Testing values at the edges of valid input ranges where defects are most likely (Correct answer)
- Analyzing network boundary latency under load
- Checking security boundaries between modules
- Measuring code coverage at module boundaries
Correct answer: Testing values at the edges of valid input ranges where defects are most likely
Boundary value analysis tests inputs at and just beyond the boundaries of valid ranges (e.g., min-1, min, max, max+1) where off-by-one errors frequently occur.
Question 7: A full-stack app's QA team finds bugs faster in staging than in production. What process improvement would most help?
- Increase production monitoring and alerting
- Implement feature flags to control rollout and enable canary releases (Correct answer)
- Hire more manual testers for production
- Reduce deployment frequency
Correct answer: Implement feature flags to control rollout and enable canary releases
Feature flags enable canary releases and gradual rollouts so production bugs are caught with minimal user impact, bridging the staging-to-production gap.
What does a 'spy' test double do differently from a 'stub'?