【edd workshop@140725】tdd introduction_andy huang
DESCRIPTION
【EDD Workshop@140725】 Topic: TDD介紹 (Test-Driven Development,測試驅動開發) Speaker: Andy HuangTRANSCRIPT
![Page 1: 【Edd workshop@140725】TDD introduction_Andy Huang](https://reader035.vdocuments.mx/reader035/viewer/2022081412/545116b5af7959cc638b6103/html5/thumbnails/1.jpg)
TDDAndy
![Page 2: 【Edd workshop@140725】TDD introduction_Andy Huang](https://reader035.vdocuments.mx/reader035/viewer/2022081412/545116b5af7959cc638b6103/html5/thumbnails/2.jpg)
Test-driven Development
● red/green/refactor where red means fail and green means pass.
![Page 3: 【Edd workshop@140725】TDD introduction_Andy Huang](https://reader035.vdocuments.mx/reader035/viewer/2022081412/545116b5af7959cc638b6103/html5/thumbnails/3.jpg)
![Page 4: 【Edd workshop@140725】TDD introduction_Andy Huang](https://reader035.vdocuments.mx/reader035/viewer/2022081412/545116b5af7959cc638b6103/html5/thumbnails/4.jpg)
The Three Laws 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.
![Page 5: 【Edd workshop@140725】TDD introduction_Andy Huang](https://reader035.vdocuments.mx/reader035/viewer/2022081412/545116b5af7959cc638b6103/html5/thumbnails/5.jpg)
Example
The subroutine add() takes two arguments and adds them together. The result is returned.
![Page 6: 【Edd workshop@140725】TDD introduction_Andy Huang](https://reader035.vdocuments.mx/reader035/viewer/2022081412/545116b5af7959cc638b6103/html5/thumbnails/6.jpg)
Live Coding
![Page 7: 【Edd workshop@140725】TDD introduction_Andy Huang](https://reader035.vdocuments.mx/reader035/viewer/2022081412/545116b5af7959cc638b6103/html5/thumbnails/7.jpg)
● fewer than two arguments?● more than two arguments?● argument isn’t numeric?
![Page 8: 【Edd workshop@140725】TDD introduction_Andy Huang](https://reader035.vdocuments.mx/reader035/viewer/2022081412/545116b5af7959cc638b6103/html5/thumbnails/8.jpg)
TDD Sucks
● I never have enough time to write the tests, once I’ve finished the main functionality.
● Testing isn’t my job, because it’s QA’s job to make sure I do quality work
● Unit tests don’t help me, because my code works perfectly the first time.
● I don’t like TDD, because I enjoy the hours I spend in my debugger
● ...
![Page 9: 【Edd workshop@140725】TDD introduction_Andy Huang](https://reader035.vdocuments.mx/reader035/viewer/2022081412/545116b5af7959cc638b6103/html5/thumbnails/9.jpg)
![Page 10: 【Edd workshop@140725】TDD introduction_Andy Huang](https://reader035.vdocuments.mx/reader035/viewer/2022081412/545116b5af7959cc638b6103/html5/thumbnails/10.jpg)
Benefits
1. Productive (Reduce your debugging time)2. Code Quality3. Over-engineering (YAGNI)4. Better Interface5. Documentation6. Lead to more modularized, flexible, and
extensible code
![Page 11: 【Edd workshop@140725】TDD introduction_Andy Huang](https://reader035.vdocuments.mx/reader035/viewer/2022081412/545116b5af7959cc638b6103/html5/thumbnails/11.jpg)
Best Practices
1. Keep the unit small2. Focused on only the results necessary to
validate its test.3. Treat your test code with the same respect as
your production code.4. Low Coupling allows each unit to be effectively
tested in isolation.5. Mock & Stub
![Page 12: 【Edd workshop@140725】TDD introduction_Andy Huang](https://reader035.vdocuments.mx/reader035/viewer/2022081412/545116b5af7959cc638b6103/html5/thumbnails/12.jpg)
Anti-Pattern
1. Avoid dependencies between test cases.2. Do not test implementation details.3. Avoid slow running tests.
![Page 13: 【Edd workshop@140725】TDD introduction_Andy Huang](https://reader035.vdocuments.mx/reader035/viewer/2022081412/545116b5af7959cc638b6103/html5/thumbnails/13.jpg)
Drawback
1. UI2. Management support is essential3. TDD is dead(?)
![Page 14: 【Edd workshop@140725】TDD introduction_Andy Huang](https://reader035.vdocuments.mx/reader035/viewer/2022081412/545116b5af7959cc638b6103/html5/thumbnails/14.jpg)
Q&A
![Page 15: 【Edd workshop@140725】TDD introduction_Andy Huang](https://reader035.vdocuments.mx/reader035/viewer/2022081412/545116b5af7959cc638b6103/html5/thumbnails/15.jpg)
Thank you
![Page 16: 【Edd workshop@140725】TDD introduction_Andy Huang](https://reader035.vdocuments.mx/reader035/viewer/2022081412/545116b5af7959cc638b6103/html5/thumbnails/16.jpg)
REFS● http://en.wikipedia.org/wiki/Test-driven_development● http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd● http://googletesting.blogspot.tw/2014/04/the-real-test-driven-development.html● http://david.heinemeierhansson.com/2014/tdd-is-dead-long-live-testing.html● https://www.facebook.com/notes/kent-beck/rip-tdd/750840194948847● https://github.com/nelsonic/learn-mocha● http://martinfowler.com/articles/mocksArentStubs.html● http://en.wikipedia.org/wiki/Mock_object● http://googletesting.blogspot.tw/