140 likes | 415 Vues
Test Driven Development. Peter Gordon. Development Approaches. Ad hoc development Writing pseudo code first Model Driven Development (MDD) Test Driven Development (TDD). What is Test Driven Development. TDD = Test First Development + Refactoring. What is Test First Development?.
E N D
Test Driven Development Peter Gordon
Development Approaches • Ad hoc development • Writing pseudo code first • Model Driven Development (MDD) • Test Driven Development (TDD)
What is Test Driven Development • TDD = Test First Development + Refactoring
What is Refactoring • Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behaviour. • A series of small behaviour preserving transformations. • A sequence of transformations can produce a significant restructuring. • Since each refactoring is small, it's less likely to go wrong. • The system is kept fully working after each small step, reducing the chances that a system can get seriously broken during the restructuring.
A list of Refactorings • Decompose Conditional • Duplicate Observed Data • Encapsulate Collection • Encapsulate Downcast • Encapsulate Field • Extract Class • Extract Interface • Extract Method • Extract Package by Gerard M. Davison • Extract Subclass • Extract Superclass • Add Parameter • Change Bidirectional Association to Unidirectional • Change Reference to Value • Change Unidirectional Association to Bidirectional • Change Value to Reference • Collapse Hierarchy • Consolidate Conditional Expression • Consolidate Duplicate Conditional Fragments • Convert Dynamic to Static Construction by Gerard M. Davison • Convert Static to Dynamic Construction by Gerard M. Davison • Form Template Method • Hide Delegate
Test Driven Development • TDD = Test First Development + Refactoring • But what are the advantages?
What are the advantages of TDD? • TDD shortens the programming feedback loop • TDD provides detailed specification (tests) • TDD promotes the development of high-quality code • TDD provides concrete evidence that your software works
What are the advantages of TDD • TDD “speaks” to programmers • TDD provides very finely grained concrete feedback on the order of minutes • TDD helps to ensure that your design is clean by focusing on creation of operations that are callable and testable • TDD supports evolutionary development.
Example in Excel • Integer to Roman in Excel • 1 to I • 2 to II • 3 to III • 4 to IV • … Available online http://www.clarkeching.com/2006/04/test_driven_dev.html
What have we shown • We can develop software in small safe steps, that’s the essence of TDD • TDD can be used to drive software development and lets design emerge • TDD ensures effective unit testing • Resulting tests verify code and act as documentation
TDD lessons learned • Effective technique for developing in all tiers • Flex (Actionscript) - Flexunit • Java - JUnit • PL/SQL – OUnit • Have to develop supporting techniques to make TDD work for you • Create Mock objects and views • Substitute visual elements during testing
TDD lessons learned • User Interface testing is the hardest • More code has to be written using TDD but that isn’t the bottleneck in Software Development • Techniques have to be learned by developers and enforced by managers • Resulting unit tests most valuable when run as part of an automated build process