CAD CAD Test-Driven Development and Agile Testing 2 — Questions and Answers
Question 1: What is the purpose of a 'test double' in TDD?
- Running the same test twice to confirm results
- Replacing a real dependency with a simplified substitute for testing (Correct answer)
- Writing two tests for every requirement
- Duplicating tests across multiple environments
Correct answer: Replacing a real dependency with a simplified substitute for testing
A test double is any object that stands in for a real dependency (stubs, mocks, fakes, spies) to isolate the unit under test from external systems.
Question 2: What distinguishes a 'mock' from a 'stub' in unit testing?
- Mocks return hardcoded values; stubs verify interactions
- Stubs return hardcoded values; mocks verify that certain interactions occurred (Correct answer)
- Mocks are used in integration tests; stubs are used in unit tests
- There is no practical difference between them
Correct answer: Stubs return hardcoded values; mocks verify that certain interactions occurred
Stubs provide canned responses to calls, while mocks also record and verify that expected interactions (method calls, parameters) occurred during the test.
Question 3: What does code coverage measure in the context of TDD?
- The percentage of user stories tested in a sprint
- The proportion of production code lines executed by automated tests (Correct answer)
- The number of defects found per test run
- The ratio of passing tests to total tests
Correct answer: The proportion of production code lines executed by automated tests
Code coverage measures what percentage of production source lines, branches, or paths are exercised by the existing automated test suite.
Question 4: In Behavior-Driven Development (BDD), what format are test scenarios typically written in?
- JUnit annotations
- Given-When-Then (Gherkin) (Correct answer)
- Arrange-Act-Assert (AAA)
- Setup-Exercise-Verify-Teardown
Correct answer: Given-When-Then (Gherkin)
BDD scenarios use the Given-When-Then (Gherkin) syntax to describe behavior in plain language understandable by both technical and non-technical stakeholders.
Question 5: What is 'regression testing' in an Agile context?
- Testing only the new features added in the current sprint
- Re-running existing tests to confirm that new changes haven't broken previously working functionality (Correct answer)
- Testing the application under load conditions
- Manual testing performed by the product owner at sprint review
Correct answer: Re-running existing tests to confirm that new changes haven't broken previously working functionality
Regression testing ensures that new code changes do not introduce defects into existing, previously verified functionality, and is ideally automated in Agile CI pipelines.
Question 6: Which practice involves the whole team — developers, testers, and the product owner — reviewing examples of system behavior to align understanding before coding?
- Sprint retrospective
- Specification by Example (SbE) / Example Mapping (Correct answer)
- Daily standup
- Backlog grooming only
Correct answer: Specification by Example (SbE) / Example Mapping
Specification by Example and Example Mapping are collaborative practices where concrete examples of behavior are discussed to eliminate ambiguity in requirements before development begins.
What is the purpose of a 'test double' in TDD?