โ† All CAD Flashcard Decks

Test-Driven Development (TDD) Flashcards

6 cards from real CAD practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 6 Test-Driven Development (TDD) flashcards as text
  1. A developer practicing Test-Driven Development (TDD) writes a test for a new feature and runs it, confirming that it fails. According to the TDD cycle, what is the immediate next step?

    Answer: Write the simplest possible production code to make the test pass.

    The TDD cycle follows the 'Red-Green-Refactor' pattern. After writing a failing test (Red), the next step is to write the minimum amount of production code necessary to make the test pass (Green). Only after the test passes should the developer consider refactoring.

  2. An agile team is adopting TDD to improve their software quality. One of the primary benefits they can expect is that TDD fosters a specific type of design. Which of the following best describes this design approach?

    Answer: Emergent Design

    TDD is a key enabler of emergent design. By writing tests first for small pieces of functionality and refactoring continuously, the software design evolves incrementally based on the actual needs of the code, rather than being planned extensively upfront.

  3. During the 'Refactor' step of the TDD cycle, what is the developer's main goal?

    Answer: To improve the internal structure and readability of the code without changing its external behavior.

    The Refactor phase is strictly for improving the quality of the code that was written to make the test pass. The key rule is to clean up the implementation (e.g., remove duplication, improve names) while ensuring all existing tests continue to pass, thus not changing the code's observable behavior.

  4. A developer is tasked with adding a complex validation rule to an existing feature. Using a strict TDD approach, which of the following should they do FIRST?

    Answer: Write a small, specific unit test that checks for the new validation rule and fails.

    Test-Driven Development always begins with writing a test before writing the production code. For a new piece of functionality, the first action is to write a failing test that defines and verifies the desired behavior.

  5. Which of the following is a common misconception about Test-Driven Development in an Agile context?

    Answer: TDD requires writing all possible tests for a feature before writing any implementation code.

    A common myth is that TDD involves writing a comprehensive suite of tests upfront. In reality, TDD is an iterative process where you write only one small, failing test at a time, then write the code to make it pass, and then refactor before moving on to the next test.

  6. An agile developer is in the 'Green' phase of the TDD cycle. They have just written some code that makes their failing test pass. However, they notice the code is inefficient and contains some duplication. What should they do NEXT?

    Answer: Move to the 'Refactor' phase to clean up the code while keeping the test green.

    After achieving a passing test (Green), the immediate next step in the TDD cycle is to Refactor. The purpose of the Green phase is solely to pass the test, even with a suboptimal solution. The subsequent Refactor phase is dedicated to improving the code's internal quality without breaking the test.