nerdexam
CiscoCisco

200-901 · Question #496

200-901 Question #496: Real Exam Question with Answer & Explanation

The question tests the understanding of the Test-Driven Development (TDD) cycle by asking to order its core steps, which follow the Red-Green-Refactor pattern.

Software Development and Design

Question

Drag and Drop Question Drag and drop the steps from the left into the order on the right to create a test-driven development cycle. Some options are used more than once. Answer:

Explanation

The question tests the understanding of the Test-Driven Development (TDD) cycle by asking to order its core steps, which follow the Red-Green-Refactor pattern.

Approach. The correct interaction is to drag and drop the steps to form the standard Test-Driven Development (TDD) cycle, often known as the Red-Green-Refactor cycle. This cycle emphasizes writing a failing test first, then writing just enough code to make the test pass, and finally refactoring the code while maintaining test integrity. Considering the five available slots and the options, the most accurate representation of one TDD cycle is:

  1. Add a test. - This initiates the 'Red' phase, where a new test is written to define a desired functionality, and it is expected to fail.
  2. Run tests. - This step verifies that the newly added test indeed fails, confirming the 'Red' state and ensuring existing tests still pass.
  3. Write some code. - This is the 'Green' phase, where the minimal code is implemented to make the failing test pass.
  4. Run tests. - After writing code, all tests are run again to confirm that the new test now passes and no existing functionality has been broken, achieving the 'Green' state.
  5. Refactor the code. - This is the 'Refactor' phase, where the implemented code is improved in terms of design, readability, and efficiency, without altering its external behavior. Tests are continuously run during refactoring to ensure no regressions are introduced. This sequence correctly uses 'Run tests' twice, aligning with the hint that some options are used more than once, and accurately represents the iterative nature of TDD.

Common mistakes.

  • common_mistake. The sequence shown in the second image (Write some code -> Add a test -> Run tests -> Refactor the code -> Add a test) is incorrect for a standard TDD cycle.
  • Starting with 'Write some code.': This contradicts the fundamental principle of TDD, which requires writing a failing test before any production code is written. Starting with code bypasses the 'Red' phase and often leads to less testable code.
  • 'Add a test' at step 2 after 'Write some code.': If code is written first, and then a test is added, the test should ideally pass immediately, negating the 'fail first' aspect of TDD.
  • Ending with 'Add a test.': While TDD is a continuous cycle, the question asks for a cycle (singular). Ending the cycle with 'Add a test' implies starting the next cycle rather than completing the current one. A single TDD iteration typically concludes after the refactoring and verification steps.
  • Incorrect placement of 'Run tests.': In the incorrect sequence, 'Run tests' appears only once in the middle. TDD requires running tests after adding a new test (to see it fail), after writing code (to see it pass), and crucially, after refactoring (to ensure no regressions).

Concept tested. The core concept tested is Test-Driven Development (TDD), specifically the correct order and rationale behind its iterative 'Red-Green-Refactor' cycle. This includes understanding the purpose of writing tests first, the minimal implementation, and continuous refactoring.

Topics

#Test-Driven Development#Software Development Process#Development Methodologies#Software Testing

Community Discussion

No community discussion yet for this question.

Full 200-901 PracticeBrowse All 200-901 Questions