Test Driven Development Part 2

15
Test Driven Test Driven Development Development Part 2 Gamal Shaaban Gamal Shaaban International Centers Orange Labs Cairo Mobile Applications & Software Development

description

The Three Rules Of TDD Legacy Code & Refactoring Code Smells Coupling And Cohesion Continues Integration THE THREE RULES OF TDD You are not allowed to write any production code unless it is to make a failing unit test pass. You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures. You are not allowed to write any more production code than is sufficient to pass the one failing unit test. Refactoring is one of the most important parts of TDD, which means you need to refine the code design as you add new tests. Refactoring should be done consistently as you increment the software, adding tests and production code. Make code easier to maintain in the future Use IDE when possible to do refactoring. Refactor Without Fear. A code smell is a surface indication that usually corresponds to a deeper problem in the system. Duplicated Code Long Method Large Class Long Parameter List Divergent Change Lazy Class Speculative Generality Temporary Field Data Class Refused Bequest Comments MiddleMan Maximize internal interaction (cohesion) easier to understand easier to test Minimize external interaction (coupling) can be used independently easier to test easier to replace easier to understand

Transcript of Test Driven Development Part 2

Page 1: Test Driven Development Part 2

Test Driven Test Driven DevelopmentDevelopment

Part 2Gamal Shaaban Gamal Shaaban International CentersOrange Labs CairoMobile Applications & Software Development

Page 2: Test Driven Development Part 2

2 Orange restricted

Page 3: Test Driven Development Part 2

3 Orange restricted

Session-2Session-2

3

• The Three Rules Of TDD• Legacy Code & Refactoring• Code Smells• Coupling And Cohesion• Continues Integration

Page 4: Test Driven Development Part 2

4 Orange restricted

THE THREE RULES OF TDD

1.You are not allowed to write any production code

unless it is to make a failing unit test pass.

2.You are not allowed to write any more of a unit test

than is sufficient to fail; and compilation failures

are failures.

3.You are not allowed to write any more production

code than is sufficient to pass the one failing unit

test.

http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd

4

Page 5: Test Driven Development Part 2

5 Orange restricted

RefactoringRefactoring Refactoring is one of the most

important parts of TDD, which means you need to refine the code design as you add new tests.

Refactoring should be done consistently as you increment the software, adding tests and production code.

Make code easier to maintain in the future

Use IDE when possible to do refactoring.

Refactor Without Fear.

5

Page 6: Test Driven Development Part 2

6 Orange restricted

Code SmellsCode Smells

A code smell is a surface indication that usually corresponds to a deeper problem in the system.

Martin FowlerMartin Fowler

http://martinfowler.com/bliki/CodeSmell.html

6

Page 7: Test Driven Development Part 2

7 Orange restricted

Smells To Be Smells To Be RefactoredRefactored

1.Duplicated Code

2.Long Method

3.Large Class

4.Long Parameter List

5.Divergent Change

6.Lazy Class

7.Speculative Generality

8.Temporary Field

9.Data Class

10.Refused Bequest

11.Comments

12.MiddleMan

Page 8: Test Driven Development Part 2

8 Orange restricted

COUPLING AND COUPLING AND COHESIONCOHESION

Maximize internal interaction (cohesion)

• easier to understand

• easier to test Minimize external interaction (coupling)

• can be used independently

• easier to test

• easier to replace

• easier to understand

8

Page 9: Test Driven Development Part 2

9 Orange restricted9

Degree of dependence among components

No dependencies Loosely coupled-some dependencies

Highly coupled-many dependencies

Page 10: Test Driven Development Part 2

10 Orange restricted

Page 11: Test Driven Development Part 2

11 Orange restricted

CONTINUES INTEGRATION

Page 12: Test Driven Development Part 2

12 Orange restricted

• Teams integrate their work multiple timesper day.

• Each integration is verified by an automated build

• Significantly reduces integration problems

• Develop cohesive software more rapidly

Source: Martin Fowler

Page 13: Test Driven Development Part 2

13 Orange restricted

Five Principles of Continuous Integration

• Environments based on stability

• Maintain a code repository

• Commit frequently and build every commit

• Make the build self-testing

• Store every build

13

Page 14: Test Driven Development Part 2

14 Orange restrictedOrange presentation

Questions?

Page 15: Test Driven Development Part 2

thanks