This document discusses Test-Driven Development (TDD). It defines TDD as writing unit tests before writing any production code. TDD helps ensure code is consistently refactored for better design. The document outlines the TDD process of writing a test, seeing it fail, writing code to pass the test, then refactoring. It discusses using TDD with legacy code by refactoring code to be testable. Sample unit tests are provided to demonstrate testing default constructor values. Benefits of TDD include better code design, earlier defect detection, and fewer defects in production releases.
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
Test-Driven Development Reference Card
1. What is Test-Driven Development (TDD)?
TDD is the practice of writing a unit test before writing any code. This can be done relatively quickly, with
the developer writing the test, then writing the code, and then running the test, all in small increments.
TDD ensures the code is consistently refactored for a better design. However, TDD isn’t a replacement
for regression suites, design specifications, QA, or code reviews.
TDD = TFD (Test Fi rst Desi gn) + Refa cto r
Contrary to popular opinion, Agile is not cowboy coding. If there’s no BDUF (Big Design Up Front),
how do you ensure your coding process has some structure? TDD is one answer.
What’s the goal of TDD?
To write “clean code that works”. (According to Ron Jeffries, http://xprogramming.com/index.php.)
What are the benefits of TDD?
• Better code design
• Earlier defect detection
• Fewer defects in production releases
• Significant drop in defect density
• Disciplined, quality-focused coding practices
e
rit hat
W t
t
e s fa i l s
t
Cha
n
c od g e
e
y
V e r i fs t s
e
a l l ta s s
p