SlideShare una empresa de Scribd logo
1 de 16
TDD
Andy
Test-driven Development
● red/green/refactor where red means fail and
green means pass.
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.
Example
The subroutine add() takes two
arguments and adds them together.
The result is returned.
Live Coding
● fewer than two arguments?
● more than two arguments?
● argument isn’t numeric?
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
● ...
Benefits
1. Productive (Reduce your debugging time)
2. Code Quality
3. Over-engineering (YAGNI)
4. Better Interface
5. Documentation
6. Lead to more modularized, flexible, and
extensible code
Best Practices
1. Keep the unit small
2. 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
Anti-Pattern
1. Avoid dependencies between test cases.
2. Do not test implementation details.
3. Avoid slow running tests.
Drawback
1. UI
2. Management support is essential
3. TDD is dead(?)
Q&A
Thank you
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/

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Pair programming and introduction to TDD
Pair programming and introduction to TDDPair programming and introduction to TDD
Pair programming and introduction to TDD
 
Developers on test
Developers on testDevelopers on test
Developers on test
 
Agile Programming Systems # TDD intro
Agile Programming Systems # TDD introAgile Programming Systems # TDD intro
Agile Programming Systems # TDD intro
 
Android Devops : Master Continuous Integration and Delivery
Android Devops : Master Continuous Integration and DeliveryAndroid Devops : Master Continuous Integration and Delivery
Android Devops : Master Continuous Integration and Delivery
 
Behavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlowBehavior Driven Development with SpecFlow
Behavior Driven Development with SpecFlow
 
ATDD with Pepino
ATDD with PepinoATDD with Pepino
ATDD with Pepino
 
TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)
 
Getting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonGetting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud Shaon
 
UPC Plone Testing Talk
UPC Plone Testing TalkUPC Plone Testing Talk
UPC Plone Testing Talk
 
TDD- Test Driven Development
TDD- Test Driven DevelopmentTDD- Test Driven Development
TDD- Test Driven Development
 
Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010
 
Put the Tests Before the Code
Put the Tests Before the CodePut the Tests Before the Code
Put the Tests Before the Code
 
Mocking in python
Mocking in pythonMocking in python
Mocking in python
 
Test Driven Development Part 1
Test Driven Development Part 1Test Driven Development Part 1
Test Driven Development Part 1
 
Nguyenvandungb seminar
Nguyenvandungb seminarNguyenvandungb seminar
Nguyenvandungb seminar
 

Similar a 【Edd workshop@140725】TDD introduction_Andy Huang

The problem with tdd
The problem with tddThe problem with tdd
The problem with tdd
Dror Helper
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Samnang Chhun
 

Similar a 【Edd workshop@140725】TDD introduction_Andy Huang (20)

Test driven development
Test driven developmentTest driven development
Test driven development
 
The problem with tdd
The problem with tddThe problem with tdd
The problem with tdd
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)
 
Tdd practices
Tdd practicesTdd practices
Tdd practices
 
TDD, the way to better software | Dan Ursu | CodeWay 2015
TDD, the way to better software | Dan Ursu | CodeWay 2015TDD, the way to better software | Dan Ursu | CodeWay 2015
TDD, the way to better software | Dan Ursu | CodeWay 2015
 
Software Testing, Everyone's responsibility
Software Testing, Everyone's responsibilitySoftware Testing, Everyone's responsibility
Software Testing, Everyone's responsibility
 
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
Ian Cooper webinar for DDD Iran: Kent beck style tdd   seven years afterIan Cooper webinar for DDD Iran: Kent beck style tdd   seven years after
Ian Cooper webinar for DDD Iran: Kent beck style tdd seven years after
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
TDD
TDDTDD
TDD
 
Is your code ready for testing?
Is your code ready for testing?Is your code ready for testing?
Is your code ready for testing?
 
Test driven development_continuous_integration
Test driven development_continuous_integrationTest driven development_continuous_integration
Test driven development_continuous_integration
 
Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test Framework
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
TDD and Unit Testing in Golang
TDD and Unit Testing in GolangTDD and Unit Testing in Golang
TDD and Unit Testing in Golang
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven Development
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 

Más de EZTABLE

天下雜誌:外資金童的第二人生
天下雜誌:外資金童的第二人生天下雜誌:外資金童的第二人生
天下雜誌:外資金童的第二人生
EZTABLE
 
Udn 20120508 c6
Udn 20120508 c6Udn 20120508 c6
Udn 20120508 c6
EZTABLE
 
EZTABLE Udn 20100528
EZTABLE Udn 20100528EZTABLE Udn 20100528
EZTABLE Udn 20100528
EZTABLE
 
EZTBALE Hksilicon 20120104
EZTBALE Hksilicon 20120104EZTBALE Hksilicon 20120104
EZTBALE Hksilicon 20120104
EZTABLE
 
EZTBALE Sina.com 20120510
EZTBALE Sina.com 20120510EZTBALE Sina.com 20120510
EZTBALE Sina.com 20120510
EZTABLE
 
EZTABLE She.com.tw citta bella 20120511
EZTABLE She.com.tw citta bella 20120511EZTABLE She.com.tw citta bella 20120511
EZTABLE She.com.tw citta bella 20120511
EZTABLE
 
EZTABLE citta bella website 20120309
EZTABLE citta bella website 20120309 EZTABLE citta bella website 20120309
EZTABLE citta bella website 20120309
EZTABLE
 
EZTBALE Inside 20110326
EZTBALE Inside 20110326 EZTBALE Inside 20110326
EZTBALE Inside 20110326
EZTABLE
 
Businessnext 20111011
Businessnext 20111011Businessnext 20111011
Businessnext 20111011
EZTABLE
 

Más de EZTABLE (17)

【EDD Workshop@140829】iOS Models-Core Data_by Boska-Lee
【EDD Workshop@140829】iOS Models-Core Data_by Boska-Lee【EDD Workshop@140829】iOS Models-Core Data_by Boska-Lee
【EDD Workshop@140829】iOS Models-Core Data_by Boska-Lee
 
【EDD Workshop@140822】淺談如何開始設計之專注美感三十年
【EDD Workshop@140822】淺談如何開始設計之專注美感三十年【EDD Workshop@140822】淺談如何開始設計之專注美感三十年
【EDD Workshop@140822】淺談如何開始設計之專注美感三十年
 
【EDD Workshop@140815】Head first grid system
【EDD Workshop@140815】Head first grid system【EDD Workshop@140815】Head first grid system
【EDD Workshop@140815】Head first grid system
 
【Edd workshop@140808】tdd spies, stubs, and mocks hao-kang den
【Edd workshop@140808】tdd spies, stubs, and mocks hao-kang den【Edd workshop@140808】tdd spies, stubs, and mocks hao-kang den
【Edd workshop@140808】tdd spies, stubs, and mocks hao-kang den
 
【Edd workshop@140808】eztable design library kc liu
【Edd workshop@140808】eztable design library kc liu【Edd workshop@140808】eztable design library kc liu
【Edd workshop@140808】eztable design library kc liu
 
【Edd workshop@140718】ios 101 for web developer zakk (yu-chen ho)
【Edd workshop@140718】ios 101 for web developer  zakk (yu-chen ho)【Edd workshop@140718】ios 101 for web developer  zakk (yu-chen ho)
【Edd workshop@140718】ios 101 for web developer zakk (yu-chen ho)
 
【EDD Workshop@140718】eztable architecture hao kang den
【EDD Workshop@140718】eztable architecture hao kang den【EDD Workshop@140718】eztable architecture hao kang den
【EDD Workshop@140718】eztable architecture hao kang den
 
Cheers 快樂工作人
Cheers 快樂工作人Cheers 快樂工作人
Cheers 快樂工作人
 
天下雜誌:外資金童的第二人生
天下雜誌:外資金童的第二人生天下雜誌:外資金童的第二人生
天下雜誌:外資金童的第二人生
 
Udn 20120508 c6
Udn 20120508 c6Udn 20120508 c6
Udn 20120508 c6
 
EZTABLE Udn 20100528
EZTABLE Udn 20100528EZTABLE Udn 20100528
EZTABLE Udn 20100528
 
EZTBALE Hksilicon 20120104
EZTBALE Hksilicon 20120104EZTBALE Hksilicon 20120104
EZTBALE Hksilicon 20120104
 
EZTBALE Sina.com 20120510
EZTBALE Sina.com 20120510EZTBALE Sina.com 20120510
EZTBALE Sina.com 20120510
 
EZTABLE She.com.tw citta bella 20120511
EZTABLE She.com.tw citta bella 20120511EZTABLE She.com.tw citta bella 20120511
EZTABLE She.com.tw citta bella 20120511
 
EZTABLE citta bella website 20120309
EZTABLE citta bella website 20120309 EZTABLE citta bella website 20120309
EZTABLE citta bella website 20120309
 
EZTBALE Inside 20110326
EZTBALE Inside 20110326 EZTBALE Inside 20110326
EZTBALE Inside 20110326
 
Businessnext 20111011
Businessnext 20111011Businessnext 20111011
Businessnext 20111011
 

Último

Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 

Último (20)

Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 

【Edd workshop@140725】TDD introduction_Andy Huang

  • 2. Test-driven Development ● red/green/refactor where red means fail and green means pass.
  • 3.
  • 4. 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.
  • 5. Example The subroutine add() takes two arguments and adds them together. The result is returned.
  • 7. ● fewer than two arguments? ● more than two arguments? ● argument isn’t numeric?
  • 8. 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 ● ...
  • 9.
  • 10. Benefits 1. Productive (Reduce your debugging time) 2. Code Quality 3. Over-engineering (YAGNI) 4. Better Interface 5. Documentation 6. Lead to more modularized, flexible, and extensible code
  • 11. Best Practices 1. Keep the unit small 2. 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
  • 12. Anti-Pattern 1. Avoid dependencies between test cases. 2. Do not test implementation details. 3. Avoid slow running tests.
  • 13. Drawback 1. UI 2. Management support is essential 3. TDD is dead(?)
  • 14. Q&A
  • 16. 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/

Notas del editor

  1. 1. You must begin by writing a unit test for the functionality that you intend to write. 2. As soon as the unit test code fails to compile, or fails an assertion, you must stop and write production code 3. But by rule 3 you can only write the production code that makes the test compile or pass, and no more.