SlideShare a Scribd company logo
1 of 10
TDD WorkshopSpies, Stubs,
and Mocks
What is a test spy?
What are stubs?
What are mocks?
When to use mocks?
When to not use mocks?
Agenda
What is a test spy?
● A test spy is a function that records
arguments, return value, the value of this
and exception thrown (if any) for all its
calls.
● A test spy can be an anonymous function
or it can wrap an existing function.
What are stubs?
● Test stubs are functions (spies) with pre-
programmed behavior. They support the
full test spy API in addition to methods
which can be used to alter the stub’s
behavior.
What are mocks?
● Mocks are fake methods (like spies) with
pre-programmed behavior (like stubs) as
well as pre-programmed expectations. A
mock will fail your test if it is not used as
expected.
When to use mocks?
● Mocks should only be used for the method
under test. In every unit test, there should
be one unit under test. If you want to
control how your unit is being used and like
stating expectations upfront (as opposed to
asserting after the fact), use a mock.
When to not use mocks?
● Mocks come with built-in expectations that may fail
your test. Thus, they enforce implementation details.
● The rule of thumb is: if you wouldn’t add an assertion
for some specific call, don’t mock it. Use a stub
instead.
● In general you should never have more than one
mock (possibly with several expectations) in a single
test.
Summary
Spy on methods
Assert values
Test your hypothesis
Challenge status quo
Further Reading
● http://sinonjs.org/docs/
● http://martinfowler.com/articles/mocksArentStubs.html
● http://dailyjs.com/2013/02/07/backbone-tutorial-11/
● https://github.com/specta/specta
● http://visionmedia.github.io/mocha/
● http://chaijs.com
● https://github.com/visionmedia/better-assert
● http://www.youtube.com/watch?v=9LfmrkyP81M
【Edd workshop@140808】tdd spies, stubs, and mocks hao-kang den

More Related Content

What's hot

Exception Handling Java
Exception Handling JavaException Handling Java
Exception Handling Javaankitgarg_er
 
Exception handling
Exception handlingException handling
Exception handlingHarry Potter
 
Monkey Testing: A Unique Style Testing Which Boosts The Power Of Manual Testing
Monkey Testing: A Unique Style Testing Which Boosts The Power Of Manual TestingMonkey Testing: A Unique Style Testing Which Boosts The Power Of Manual Testing
Monkey Testing: A Unique Style Testing Which Boosts The Power Of Manual TestingBugRaptors
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in javachauhankapil
 
Java Exceptions and Exception Handling
 Java  Exceptions and Exception Handling Java  Exceptions and Exception Handling
Java Exceptions and Exception HandlingMaqdamYasir
 
Defencive programming
Defencive programmingDefencive programming
Defencive programmingAsha Sari
 

What's hot (12)

Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
Exceptions
ExceptionsExceptions
Exceptions
 
Exception Handling Java
Exception Handling JavaException Handling Java
Exception Handling Java
 
Java unit 11
Java unit 11Java unit 11
Java unit 11
 
Exception handling
Exception handlingException handling
Exception handling
 
Monkey Testing: A Unique Style Testing Which Boosts The Power Of Manual Testing
Monkey Testing: A Unique Style Testing Which Boosts The Power Of Manual TestingMonkey Testing: A Unique Style Testing Which Boosts The Power Of Manual Testing
Monkey Testing: A Unique Style Testing Which Boosts The Power Of Manual Testing
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Java Exceptions and Exception Handling
 Java  Exceptions and Exception Handling Java  Exceptions and Exception Handling
Java Exceptions and Exception Handling
 
Z blue exception
Z blue   exceptionZ blue   exception
Z blue exception
 
Defencive programming
Defencive programmingDefencive programming
Defencive programming
 
Exception handling
Exception handlingException handling
Exception handling
 

Similar to 【Edd workshop@140808】tdd spies, stubs, and mocks hao-kang den

Writing good unit test
Writing good unit testWriting good unit test
Writing good unit testLucy Lu
 
Strategic Testing (CodeMash 2016)
Strategic Testing (CodeMash 2016)Strategic Testing (CodeMash 2016)
Strategic Testing (CodeMash 2016)Dmitry Sharkov
 
Unit test documentation
Unit test documentationUnit test documentation
Unit test documentationAnjan Debnath
 
Unit Testing in Angular
Unit Testing in AngularUnit Testing in Angular
Unit Testing in AngularKnoldus Inc.
 
Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)Abhijeet Vaikar
 
Get the Balance Right: Acceptance Test Driven Development, GUI Automation and...
Get the Balance Right: Acceptance Test Driven Development, GUI Automation and...Get the Balance Right: Acceptance Test Driven Development, GUI Automation and...
Get the Balance Right: Acceptance Test Driven Development, GUI Automation and...Michael Larsen
 
Unit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile AppsUnit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile AppsMarcelo Busico
 
STOP! You're Testing Too Much - Shawn Wallace
STOP!  You're Testing Too Much - Shawn WallaceSTOP!  You're Testing Too Much - Shawn Wallace
STOP! You're Testing Too Much - Shawn WallaceQA or the Highway
 
Stop! you're testing too much
Stop!  you're testing too muchStop!  you're testing too much
Stop! you're testing too muchShawn Wallace
 
Testing Spark and Scala
Testing Spark and ScalaTesting Spark and Scala
Testing Spark and Scaladatamantra
 
Orthogonal Array Testing
Orthogonal Array TestingOrthogonal Array Testing
Orthogonal Array TestingHiraQureshi22
 
Effective Unit Testing
Effective Unit TestingEffective Unit Testing
Effective Unit TestingEyal Kenig
 
Evil Tester's Guide to Agile Testing
Evil Tester's Guide to Agile TestingEvil Tester's Guide to Agile Testing
Evil Tester's Guide to Agile TestingAlan Richardson
 
A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)Thierry Gayet
 
Orthogonal array testing course
Orthogonal array testing courseOrthogonal array testing course
Orthogonal array testing courseNarayanan Palani
 
introduction to Unit testing in Angular.pptx
introduction to Unit testing in Angular.pptxintroduction to Unit testing in Angular.pptx
introduction to Unit testing in Angular.pptxKnoldus Inc.
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven DevelopmentFerdous Mahmud Shaon
 
Exploratory testing
Exploratory testingExploratory testing
Exploratory testingISsoft
 
Test-Driven Development (TDD) in Swift
Test-Driven Development (TDD) in SwiftTest-Driven Development (TDD) in Swift
Test-Driven Development (TDD) in SwiftAmey Tavkar
 

Similar to 【Edd workshop@140808】tdd spies, stubs, and mocks hao-kang den (20)

Writing good unit test
Writing good unit testWriting good unit test
Writing good unit test
 
Strategic Testing (CodeMash 2016)
Strategic Testing (CodeMash 2016)Strategic Testing (CodeMash 2016)
Strategic Testing (CodeMash 2016)
 
Unit test documentation
Unit test documentationUnit test documentation
Unit test documentation
 
Unit Testing in Angular
Unit Testing in AngularUnit Testing in Angular
Unit Testing in Angular
 
Test Infected
Test InfectedTest Infected
Test Infected
 
Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)
 
Get the Balance Right: Acceptance Test Driven Development, GUI Automation and...
Get the Balance Right: Acceptance Test Driven Development, GUI Automation and...Get the Balance Right: Acceptance Test Driven Development, GUI Automation and...
Get the Balance Right: Acceptance Test Driven Development, GUI Automation and...
 
Unit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile AppsUnit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile Apps
 
STOP! You're Testing Too Much - Shawn Wallace
STOP!  You're Testing Too Much - Shawn WallaceSTOP!  You're Testing Too Much - Shawn Wallace
STOP! You're Testing Too Much - Shawn Wallace
 
Stop! you're testing too much
Stop!  you're testing too muchStop!  you're testing too much
Stop! you're testing too much
 
Testing Spark and Scala
Testing Spark and ScalaTesting Spark and Scala
Testing Spark and Scala
 
Orthogonal Array Testing
Orthogonal Array TestingOrthogonal Array Testing
Orthogonal Array Testing
 
Effective Unit Testing
Effective Unit TestingEffective Unit Testing
Effective Unit Testing
 
Evil Tester's Guide to Agile Testing
Evil Tester's Guide to Agile TestingEvil Tester's Guide to Agile Testing
Evil Tester's Guide to Agile Testing
 
A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)
 
Orthogonal array testing course
Orthogonal array testing courseOrthogonal array testing course
Orthogonal array testing course
 
introduction to Unit testing in Angular.pptx
introduction to Unit testing in Angular.pptxintroduction to Unit testing in Angular.pptx
introduction to Unit testing in Angular.pptx
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven Development
 
Exploratory testing
Exploratory testingExploratory testing
Exploratory testing
 
Test-Driven Development (TDD) in Swift
Test-Driven Development (TDD) in SwiftTest-Driven Development (TDD) in Swift
Test-Driven Development (TDD) in Swift
 

More from EZTABLE

【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-LeeEZTABLE
 
【EDD Workshop@140822】淺談如何開始設計之專注美感三十年
【EDD Workshop@140822】淺談如何開始設計之專注美感三十年【EDD Workshop@140822】淺談如何開始設計之專注美感三十年
【EDD Workshop@140822】淺談如何開始設計之專注美感三十年EZTABLE
 
【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 systemEZTABLE
 
【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 liuEZTABLE
 
【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)EZTABLE
 
【Edd workshop@140725】TDD introduction_Andy Huang
【Edd workshop@140725】TDD introduction_Andy Huang 【Edd workshop@140725】TDD introduction_Andy Huang
【Edd workshop@140725】TDD introduction_Andy Huang EZTABLE
 
【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 denEZTABLE
 
Cheers 快樂工作人
Cheers 快樂工作人Cheers 快樂工作人
Cheers 快樂工作人EZTABLE
 
天下雜誌:外資金童的第二人生
天下雜誌:外資金童的第二人生天下雜誌:外資金童的第二人生
天下雜誌:外資金童的第二人生EZTABLE
 
Udn 20120508 c6
Udn 20120508 c6Udn 20120508 c6
Udn 20120508 c6EZTABLE
 
EZTABLE Udn 20100528
EZTABLE Udn 20100528EZTABLE Udn 20100528
EZTABLE Udn 20100528EZTABLE
 
EZTBALE Hksilicon 20120104
EZTBALE Hksilicon 20120104EZTBALE Hksilicon 20120104
EZTBALE Hksilicon 20120104EZTABLE
 
EZTBALE Sina.com 20120510
EZTBALE Sina.com 20120510EZTBALE Sina.com 20120510
EZTBALE Sina.com 20120510EZTABLE
 
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 20120511EZTABLE
 
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 20111011EZTABLE
 

More from 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】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@140725】TDD introduction_Andy Huang
【Edd workshop@140725】TDD introduction_Andy Huang 【Edd workshop@140725】TDD introduction_Andy Huang
【Edd workshop@140725】TDD introduction_Andy Huang
 
【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
 

Recently uploaded

VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 

Recently uploaded (20)

VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 

【Edd workshop@140808】tdd spies, stubs, and mocks hao-kang den

  • 2. What is a test spy? What are stubs? What are mocks? When to use mocks? When to not use mocks? Agenda
  • 3. What is a test spy? ● A test spy is a function that records arguments, return value, the value of this and exception thrown (if any) for all its calls. ● A test spy can be an anonymous function or it can wrap an existing function.
  • 4. What are stubs? ● Test stubs are functions (spies) with pre- programmed behavior. They support the full test spy API in addition to methods which can be used to alter the stub’s behavior.
  • 5. What are mocks? ● Mocks are fake methods (like spies) with pre-programmed behavior (like stubs) as well as pre-programmed expectations. A mock will fail your test if it is not used as expected.
  • 6. When to use mocks? ● Mocks should only be used for the method under test. In every unit test, there should be one unit under test. If you want to control how your unit is being used and like stating expectations upfront (as opposed to asserting after the fact), use a mock.
  • 7. When to not use mocks? ● Mocks come with built-in expectations that may fail your test. Thus, they enforce implementation details. ● The rule of thumb is: if you wouldn’t add an assertion for some specific call, don’t mock it. Use a stub instead. ● In general you should never have more than one mock (possibly with several expectations) in a single test.
  • 8. Summary Spy on methods Assert values Test your hypothesis Challenge status quo
  • 9. Further Reading ● http://sinonjs.org/docs/ ● http://martinfowler.com/articles/mocksArentStubs.html ● http://dailyjs.com/2013/02/07/backbone-tutorial-11/ ● https://github.com/specta/specta ● http://visionmedia.github.io/mocha/ ● http://chaijs.com ● https://github.com/visionmedia/better-assert ● http://www.youtube.com/watch?v=9LfmrkyP81M