【edd workshop@140725】tdd introduction_andy huang

16
TDD Andy

Upload: eztable

Post on 29-Oct-2014

80 views

Category:

Engineering


0 download

DESCRIPTION

【EDD Workshop@140725】 Topic: TDD介紹 (Test-Driven Development,測試驅動開發) Speaker: Andy Huang

TRANSCRIPT

Page 1: 【Edd workshop@140725】TDD introduction_Andy Huang

TDDAndy

Page 2: 【Edd workshop@140725】TDD introduction_Andy Huang

Test-driven Development

● red/green/refactor where red means fail and green means pass.

Page 3: 【Edd workshop@140725】TDD introduction_Andy Huang
Page 4: 【Edd workshop@140725】TDD introduction_Andy Huang

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

Example

The subroutine add() takes two arguments and adds them together. The result is returned.

Page 6: 【Edd workshop@140725】TDD introduction_Andy Huang

Live Coding

Page 7: 【Edd workshop@140725】TDD introduction_Andy Huang

● fewer than two arguments?● more than two arguments?● argument isn’t numeric?

Page 8: 【Edd workshop@140725】TDD introduction_Andy Huang

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
Page 10: 【Edd workshop@140725】TDD introduction_Andy Huang

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

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

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

Drawback

1. UI2. Management support is essential3. TDD is dead(?)

Page 14: 【Edd workshop@140725】TDD introduction_Andy Huang

Q&A

Page 15: 【Edd workshop@140725】TDD introduction_Andy Huang

Thank you

Page 16: 【Edd workshop@140725】TDD introduction_Andy Huang

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/