210 likes | 451 Views
Test Driven Development. Daniel Brown. dxb17u. Introduction. Software Development Technique. Based on Unit Testing. Proposed by Kent Beck in 2003. Originates from Extreme Programming (XP). Test Driven Development (TDD) is a feature of XP. Main goal is to produce “clean code that
E N D
Test Driven Development Daniel Brown dxb17u
Introduction • Software Development Technique • Based on Unit Testing • Proposed by Kent Beck in 2003. • Originates from Extreme Programming (XP) • Test Driven Development (TDD) is a feature • of XP • Main goal is to produce “clean code that • works” (Kent Beck)
What is TDD? • TDD has only two simple rules: 1. Write code only if a test has failed 2. Eliminate Duplication at each stage • These two rules imply an order to the • tasks of programming.
TDD Cycle Write a test that fails Write code to pass the test Fail Ensure code passes test Pass Refactor • Process is commonly described as the red/green/refactor programming mantra
Refactoring • “Process of improving the design of code • without changing its behaviour”. • Used to eliminate duplication in TDD. • Other goals include: • Improving extensibility • Improving performance • Changing code to adhere to coding • standards
Direct Implications • Reduces defect density of the code • Programmers become more focused on • system requirements. • Unit Tests can become part of the system • documentation. • Increases developer understanding of • parts of the system.
TDD and XP Values • TDD development helps to support the main values of XP. 1. Communication 2. Feedback 3. Simplicity 4. Courage • Particularly relevant to agile development • methodologies.
Communication • Improves Customer-Developer Communication • More likely to involve customer in • development • Improves Developer-Developer communication • Unit tests proved a means to understand • code • Collective Code ownership
Feedback • TDD maximises system feedback and customer feedback. • Constant unit testing • Short iterations through TDD cycle • Regular system releases to customer. • Developers can respond to customer • feedback efficiently.
Simplicity • Each function is implemented one by one • Reduces scope creep • Customer has more control over the • system being developed
Courage • Keeps developers focused on • implementing the current requirement • Eliminates developer “fear” • Beck states that fear has a number of • negative effects.
Drawbacks • Unit tests which repeatedly failed. • Large number of tests = maintenance • overhead. • Tests are commonly written by the • developer. • Vast number of tests passing may bring a • false sense of security.