200-901 · Question #121
What is the first development task in test-driven development?
The correct answer is B. Write a failing test case for a desired function. The TDD cycle always begins with writing a failing test case (the 'Red' phase of Red-Green-Refactor). You define what the code should do by writing a test for it before any implementation exists. Because no code exists yet, the test must fail - this confirms the test is…
Question
What is the first development task in test-driven development?
Options
- AWrite code that implements a desired function.
- BWrite a failing test case for a desired function.
- CWrite a passing test case for existing code.
- DReverse engineer the code for a desired function.
How the community answered
(56 responses)- A4% (2)
- B93% (52)
- C2% (1)
- D2% (1)
Explanation
The TDD cycle always begins with writing a failing test case (the 'Red' phase of Red-Green-Refactor). You define what the code should do by writing a test for it before any implementation exists. Because no code exists yet, the test must fail - this confirms the test is actually testing something meaningful. Only after a failing test exists do you write implementation code (Choice A) to make it pass. Choice C describes writing a passing test for existing code, which is retroactive testing, not TDD. Choice D (reverse engineering) has no place in TDD methodology.
Topics
Community Discussion
No community discussion yet for this question.