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

Final DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualFinal DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manual
BalamuruganV28
 
Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..
MaherOthman7
 
Online crime reporting system project.pdf
Online crime reporting system project.pdfOnline crime reporting system project.pdf
Online crime reporting system project.pdf
Kamal Acharya
 

Último (20)

Introduction to Artificial Intelligence and History of AI
Introduction to Artificial Intelligence and History of AIIntroduction to Artificial Intelligence and History of AI
Introduction to Artificial Intelligence and History of AI
 
Final DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualFinal DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manual
 
AI in Healthcare Innovative use cases and applications.pdf
AI in Healthcare Innovative use cases and applications.pdfAI in Healthcare Innovative use cases and applications.pdf
AI in Healthcare Innovative use cases and applications.pdf
 
Theory for How to calculation capacitor bank
Theory for How to calculation capacitor bankTheory for How to calculation capacitor bank
Theory for How to calculation capacitor bank
 
Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..
 
Introduction to Arduino Programming: Features of Arduino
Introduction to Arduino Programming: Features of ArduinoIntroduction to Arduino Programming: Features of Arduino
Introduction to Arduino Programming: Features of Arduino
 
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
 
Geometric constructions Engineering Drawing.pdf
Geometric constructions Engineering Drawing.pdfGeometric constructions Engineering Drawing.pdf
Geometric constructions Engineering Drawing.pdf
 
Diploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfDiploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdf
 
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdfInstruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
 
Supermarket billing system project report..pdf
Supermarket billing system project report..pdfSupermarket billing system project report..pdf
Supermarket billing system project report..pdf
 
Electrical shop management system project report.pdf
Electrical shop management system project report.pdfElectrical shop management system project report.pdf
Electrical shop management system project report.pdf
 
Online crime reporting system project.pdf
Online crime reporting system project.pdfOnline crime reporting system project.pdf
Online crime reporting system project.pdf
 
Intelligent Agents, A discovery on How A Rational Agent Acts
Intelligent Agents, A discovery on How A Rational Agent ActsIntelligent Agents, A discovery on How A Rational Agent Acts
Intelligent Agents, A discovery on How A Rational Agent Acts
 
Operating System chapter 9 (Virtual Memory)
Operating System chapter 9 (Virtual Memory)Operating System chapter 9 (Virtual Memory)
Operating System chapter 9 (Virtual Memory)
 
Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1
 
Low rpm Generator for efficient energy harnessing from a two stage wind turbine
Low rpm Generator for efficient energy harnessing from a two stage wind turbineLow rpm Generator for efficient energy harnessing from a two stage wind turbine
Low rpm Generator for efficient energy harnessing from a two stage wind turbine
 
Insurance management system project report.pdf
Insurance management system project report.pdfInsurance management system project report.pdf
Insurance management system project report.pdf
 
Raashid final report on Embedded Systems
Raashid final report on Embedded SystemsRaashid final report on Embedded Systems
Raashid final report on Embedded Systems
 
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfInvolute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
 

【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.