First Development Task in Test-Driven Development
Short answer
B Write a failing test case for a desired function before writing any implementation code.
Question
Key Takeaways
Test-driven development begins by writing a failing test case that specifies the desired behavior of a function before any implementation code exists. Option B is correct because the test-first failure is the defining starting point of TDD, while writing implementation code, reverse engineering, or testing existing code all violate the methodology's test-before-code ordering.
Expert Analysis
The first step in TDD is to write a failing test case that defines the desired behavior of the function to be implemented. Only after the test is written does the developer write the minimal code necessary to make the test pass.
Option B correctly identifies the starting point of test-driven development: writing a failing test case for a desired function. In TDD, the test is written before any implementation code exists, which means the test will fail on its first run because the function it references has not been created. This failure is intentional and expected — it signals that the test is actually exercising the new behavior rather than trivially passing. The test encodes the specification for the desired function, describing what inputs should produce what outputs, and only then does the developer move to writing the function itself. The test acts as both a design tool and an executable specification, shaping the interface and behavior of the code before a single line of implementation is typed.
Option A describes writing code that implements a desired function. This is the second phase of the TDD cycle, not the first. Once the failing test exists, the developer writes the minimal amount of code needed to make that test pass — no more, no less. Placing implementation first inverts the methodology entirely and eliminates the test-first discipline that gives TDD its name. Without a pre-existing test, there is nothing to drive the design of the function's interface, and the developer risks building more than what is needed or missing edge cases that a test would have surfaced.
Option C suggests reverse engineering code for a desired function. Reverse engineering has no role in the TDD workflow. TDD is a forward-looking, constructive practice where behavior is specified through tests and then built to satisfy those tests. There is no existing code to reverse engineer at the outset of a TDD cycle, because the desired function does not yet exist. Reverse engineering implies analyzing something already built to understand its inner workings, which contradicts the greenfield, test-first nature of TDD.
Option D proposes writing a passing test case for existing code. This describes retroactive test coverage — adding tests to code that already works — which is the opposite of test-driven development. A test written for existing code that passes immediately provides no design guidance and does not drive the implementation decisions. In genuine TDD, the test must fail first, proving that the desired behavior is not yet implemented and that the test is meaningful. A test that passes on the first run against existing code is verification, not development driven by tests.
The Red-Green-Refactor Cycle
The unspoken mechanism this question relies on is the three-phase rhythm that gives TDD its structure: Red, Green, and Refactor. The "Red" phase corresponds to option B — the test is written and run, and it fails because the target function does not exist or does not yet exhibit the expected behavior. The color red signifies the failing assertion. The "Green" phase corresponds to option A — the developer writes just enough implementation code to turn the failing test green, meaning all assertions pass. The "Refactor" phase then allows the developer to clean up the code — renaming variables, extracting helper functions, or eliminating duplication — while the existing test suite confirms that behavior remains correct. Each new unit of behavior enters the codebase by repeating this cycle, so the test always precedes the code. This strict ordering is what distinguishes TDD from simply writing tests at some point during the development process, and it is why option B — not A, C, or D — represents the first development task.
Exam Strategy
When a TDD question asks about ordering or the first step, anchor on the Red-Green-Refactor cycle. The first phase is always Red — a test that fails because the function does not yet exist. Eliminate any option that places implementation before testing, that describes testing existing code, or that introduces non-TDD activities like reverse engineering. The test must fail first to prove it exercises new behavior.
Related Analysis
Practice All 200-901 Questions
Access 105 questions with complete answers and detailed explanations.
View Full 200-901 Practice Test →