nerdexam
Cisco

200-901 · Question #273

Why is refactoring done during test-driven development?

The correct answer is B. to improve maintainability and readability. In Test-Driven Development (TDD), the cycle is Red → Green → Refactor. After writing a failing test (Red) and making it pass with minimal code (Green), refactoring is performed to improve the internal quality of the code without changing its behavior. The goal is to improve…

Software Development and Design

Question

Why is refactoring done during test-driven development?

Options

  • Ato enable larger objects and longer methods
  • Bto improve maintainability and readability
  • Cto ensure that the previous uses of the objects are explained
  • Dto ensure the duplication of essential code

How the community answered

(16 responses)
  • A
    6% (1)
  • B
    94% (15)

Explanation

In Test-Driven Development (TDD), the cycle is Red → Green → Refactor. After writing a failing test (Red) and making it pass with minimal code (Green), refactoring is performed to improve the internal quality of the code without changing its behavior. The goal is to improve maintainability (easier to extend and modify) and readability (easier for other developers to understand). The existing tests serve as a safety net to confirm that refactoring did not break any functionality. Options A and D describe anti-patterns (larger objects, duplicated code) that refactoring is meant to eliminate. Option C is not a goal of refactoring.

Topics

#Refactoring#Test-Driven Development (TDD)#Code Quality#Software Maintainability

Community Discussion

No community discussion yet for this question.

Full 200-901 Practice