SlideShare una empresa de Scribd logo
1 de 58
Testing Gone Right
  from RubyConf 2011 and others
      @jwo - Jesse Wolgamott
What We’ll Talk Abouts
What We’ll Talk Abouts

• Mock is not a 4 letter word
• Fast tests. Really Fast.
• Rails Models
Mock is not a 4 letter
        word
Mocks
Mocks

• Mocks are not stubs
Mocks

• Mocks are not stubs
• Mocks assert Messages
Mocks

• Mocks are not stubs
• Mocks assert Messages
• Assert on state => Stubbing
Mocks

• Mocks are not stubs
• Mocks assert Messages
• Assert on state => Stubbing
• Assert on messages => Mocking
Ruby + OOP + Mock
Ruby + OOP + Mock

• is goood
Ruby + OOP + Mock

• is goood
• Objects should tell objects to do things
Ruby + OOP + Mock

• is goood
• Objects should tell objects to do things
• (Tell don’t ask)
Ruby + OOP + Mock

• is goood
• Objects should tell objects to do things
• (Tell don’t ask)
• You tell to do things using messages
Mock Roles

• Instead of mocking objects, try to mock
  roles
• Wanting to mock concrete objects is a
  design smell
Example
Example

• Restaurant system reserves tables
• Instead of your interface talking to a
  ReservationService:
• Talk to ReservationInterfaceHandler
Message Example
 class ReservationInterface
   def initialize(handler)
     @handler = handler
   end

   def select_table(table)
     @table = table
   end

   def submit_request
     @handler.reserve(@table)
   end
 end
And to Spec it
describe ReservationInterface do

 let(:table){something_interesting_here}
 it "should tell the handler to reserve a table" do
   handler = double('reservation_handler')
   handler.should_receive(:reserve).with(table)
   machine = ReservationInterface.new(handler)
   machine.select_table(table)
   machine.submit_request
 end
Watch Out!
On APIs

• Only Mock Types you own
• Don’t mock boundary objects
• If you do, you’ll duplicate code -> CODE
  SMELL
Other Mock Smells
Other Mock Smells

• Having to setup more than 3 lines -- that’s a
  code smell
Other Mock Smells

• Having to setup more than 3 lines -- that’s a
  code smell
• Mocking concrete objects -- that’s a code
  smell
Other Mock Smells

• Having to setup more than 3 lines -- that’s a
  code smell
• Mocking concrete objects -- that’s a code
  smell
• When tests go brittle and developers
  declare mocks suck -- that’s a code smell
However
However
• If you have a “standard” Rails app,
  programmed procedurally:
However
• If you have a “standard” Rails app,
  programmed procedurally:
• Mocks are not for you
However
• If you have a “standard” Rails app,
  programmed procedurally:
• Mocks are not for you
• If you encapulate your code. If you hide
  information (OOP). If you use messages:
However
• If you have a “standard” Rails app,
  programmed procedurally:
• Mocks are not for you
• If you encapulate your code. If you hide
  information (OOP). If you use messages:
• Mocks are for you!
Mocks Don’t Suck
Mocks Don’t Suck
• If your code is hard to test, you need better
  code
Mocks Don’t Suck
• If your code is hard to test, you need better
  code
• If you have a test that is HARD to setup,
  your class (or test) is doing too much
Mocks Don’t Suck
• If your code is hard to test, you need better
  code
• If you have a test that is HARD to setup,
  your class (or test) is doing too much
• If you see tests with uber-mocks, the
  answer is not to delete mocks. It’s to
  isolate your tests
Fast Rails Tests
Out of the Box
Out of the Box

• Most Rails apps start as CRUD apps
Out of the Box

• Most Rails apps start as CRUD apps
• Tests start fast-ish
Out of the Box

• Most Rails apps start as CRUD apps
• Tests start fast-ish
• Like a frog, we don’t notice the increase
“fast” tests


• Tests should run in under a second
• The entire rspec test suite
How?


• Don’t load rails
Example
             Spec Run
                        Real Time
               Time

With Rails     .07 s      8.1 s


Without
             0.0007 s      .8 s
 Rails
Avoid Factories
Avoid Factories

• Instead, extract your code to classes with
  one single responsibility
Avoid Factories

• Instead, extract your code to classes with
  one single responsibility
• Rather than knowing everything about your
  object
Avoid Factories

• Instead, extract your code to classes with
  one single responsibility
• Rather than knowing everything about your
  object
• Or, load methods via modules
Rails Models
Rails Models

• Are Fat.
Rails Models

• Are Fat.
• Wait, isn’t that good?
Rails Models

• Are Fat.
• Wait, isn’t that good?
• It’s better than controller logic
Rails Models

• Are Fat.
• Wait, isn’t that good?
• It’s better than controller logic
• But no.
What then?
What then?

• Your models can have validations
What then?

• Your models can have validations
• Call out to policy or decision classes for
  business logic
What then?

• Your models can have validations
• Call out to policy or decision classes for
  business logic
• Use Ruby Classes
What then?

• Your models can have validations
• Call out to policy or decision classes for
  business logic
• Use Ruby Classes
• Use Presenters
Example

• Example of building a burrito that is
  delicious, and can know it’s delicious
• In Isolation: https://gist.github.com/1281093
• Using Modules: https://gist.github.com/
  1281064
Credits
Why you don’t get mock objects @gregmoeck

Your tests are lying to you        @chrismdp

Fast Rails talk at gogoruco 2011   @coreyhaines
Testing in Isolation.
                                   @garybernhardt
destroyalldoftware.com

Más contenido relacionado

La actualidad más candente

Perfect Styling - How to write better CSS
Perfect Styling - How to write better CSSPerfect Styling - How to write better CSS
Perfect Styling - How to write better CSSArtem Tabalin
 
Dont Try Kotlin on The Backend or You'll Get Hooked
Dont Try Kotlin on The Backend or You'll Get HookedDont Try Kotlin on The Backend or You'll Get Hooked
Dont Try Kotlin on The Backend or You'll Get HookedAlex Fedorov
 
Javascript classes and scoping
Javascript classes and scopingJavascript classes and scoping
Javascript classes and scopingPatrick Sheridan
 
QA / Testing Tools, Automation Testing, Online & Classroom Training
QA / Testing Tools, Automation Testing, Online & Classroom Training QA / Testing Tools, Automation Testing, Online & Classroom Training
QA / Testing Tools, Automation Testing, Online & Classroom Training AnanthReddy38
 
Funtional Ruby - Mikhail Bortnyk
Funtional Ruby - Mikhail BortnykFuntional Ruby - Mikhail Bortnyk
Funtional Ruby - Mikhail BortnykRuby Meditation
 
Herding a Cat with Antlers - Catalyst 5.80
Herding a Cat with Antlers - Catalyst 5.80Herding a Cat with Antlers - Catalyst 5.80
Herding a Cat with Antlers - Catalyst 5.80Tomas Doran
 
Frederick web meetup slides
Frederick web meetup slidesFrederick web meetup slides
Frederick web meetup slidesPat Zearfoss
 
Kevin Whinnery: Write Better JavaScript
Kevin Whinnery: Write Better JavaScriptKevin Whinnery: Write Better JavaScript
Kevin Whinnery: Write Better JavaScriptAxway Appcelerator
 
2 the essentials of effective java
2 the essentials of effective java2 the essentials of effective java
2 the essentials of effective javaHonnix Liang
 

La actualidad más candente (10)

Perfect Styling - How to write better CSS
Perfect Styling - How to write better CSSPerfect Styling - How to write better CSS
Perfect Styling - How to write better CSS
 
Dont Try Kotlin on The Backend or You'll Get Hooked
Dont Try Kotlin on The Backend or You'll Get HookedDont Try Kotlin on The Backend or You'll Get Hooked
Dont Try Kotlin on The Backend or You'll Get Hooked
 
Javascript classes and scoping
Javascript classes and scopingJavascript classes and scoping
Javascript classes and scoping
 
QA / Testing Tools, Automation Testing, Online & Classroom Training
QA / Testing Tools, Automation Testing, Online & Classroom Training QA / Testing Tools, Automation Testing, Online & Classroom Training
QA / Testing Tools, Automation Testing, Online & Classroom Training
 
Funtional Ruby - Mikhail Bortnyk
Funtional Ruby - Mikhail BortnykFuntional Ruby - Mikhail Bortnyk
Funtional Ruby - Mikhail Bortnyk
 
Software Patterns
Software PatternsSoftware Patterns
Software Patterns
 
Herding a Cat with Antlers - Catalyst 5.80
Herding a Cat with Antlers - Catalyst 5.80Herding a Cat with Antlers - Catalyst 5.80
Herding a Cat with Antlers - Catalyst 5.80
 
Frederick web meetup slides
Frederick web meetup slidesFrederick web meetup slides
Frederick web meetup slides
 
Kevin Whinnery: Write Better JavaScript
Kevin Whinnery: Write Better JavaScriptKevin Whinnery: Write Better JavaScript
Kevin Whinnery: Write Better JavaScript
 
2 the essentials of effective java
2 the essentials of effective java2 the essentials of effective java
2 the essentials of effective java
 

Destacado

Emprendimiento yennifer aguirre
Emprendimiento yennifer aguirreEmprendimiento yennifer aguirre
Emprendimiento yennifer aguirreysm123
 
Agile in 90minutes
Agile in 90minutesAgile in 90minutes
Agile in 90minutesallan kelly
 
The horror story
The horror storyThe horror story
The horror storyceebee2009
 
Planning for Value
Planning for ValuePlanning for Value
Planning for Valueallan kelly
 
Xxxxxx karim a hamir 2015 resume
Xxxxxx karim a  hamir 2015 resumeXxxxxx karim a  hamir 2015 resume
Xxxxxx karim a hamir 2015 resumeKarim Hamir
 
Land preparation and potato planting
Land preparation and potato plantingLand preparation and potato planting
Land preparation and potato plantingHarahagazwe
 
Test Driven Design
Test Driven DesignTest Driven Design
Test Driven DesignSaad Ahmed
 
No Projects - Beyond Projects (Refreshed version)
No Projects - Beyond Projects (Refreshed version)No Projects - Beyond Projects (Refreshed version)
No Projects - Beyond Projects (Refreshed version)allan kelly
 
Prosci Change Management Workshop for Project Managers Info Webinar (30 mins)
Prosci Change Management Workshop for Project Managers Info Webinar (30 mins)Prosci Change Management Workshop for Project Managers Info Webinar (30 mins)
Prosci Change Management Workshop for Project Managers Info Webinar (30 mins)Prosci ANZ
 
Zero to the Cloud with @NetflixOSS
Zero to the Cloud with @NetflixOSSZero to the Cloud with @NetflixOSS
Zero to the Cloud with @NetflixOSSMike McGarr
 

Destacado (12)

Emprendimiento yennifer aguirre
Emprendimiento yennifer aguirreEmprendimiento yennifer aguirre
Emprendimiento yennifer aguirre
 
Agile in 90minutes
Agile in 90minutesAgile in 90minutes
Agile in 90minutes
 
The horror story
The horror storyThe horror story
The horror story
 
Planning for Value
Planning for ValuePlanning for Value
Planning for Value
 
Xxxxxx karim a hamir 2015 resume
Xxxxxx karim a  hamir 2015 resumeXxxxxx karim a  hamir 2015 resume
Xxxxxx karim a hamir 2015 resume
 
Land preparation and potato planting
Land preparation and potato plantingLand preparation and potato planting
Land preparation and potato planting
 
Dev ops for devs
Dev ops for devsDev ops for devs
Dev ops for devs
 
Test Driven Design
Test Driven DesignTest Driven Design
Test Driven Design
 
No Projects - Beyond Projects (Refreshed version)
No Projects - Beyond Projects (Refreshed version)No Projects - Beyond Projects (Refreshed version)
No Projects - Beyond Projects (Refreshed version)
 
Prosci Change Management Workshop for Project Managers Info Webinar (30 mins)
Prosci Change Management Workshop for Project Managers Info Webinar (30 mins)Prosci Change Management Workshop for Project Managers Info Webinar (30 mins)
Prosci Change Management Workshop for Project Managers Info Webinar (30 mins)
 
Zero to the Cloud with @NetflixOSS
Zero to the Cloud with @NetflixOSSZero to the Cloud with @NetflixOSS
Zero to the Cloud with @NetflixOSS
 
Corona effect
Corona effectCorona effect
Corona effect
 

Similar a Testing gone-right

Learn To Test Like A Grumpy Programmer - 3 hour workshop
Learn To Test Like A Grumpy Programmer - 3 hour workshopLearn To Test Like A Grumpy Programmer - 3 hour workshop
Learn To Test Like A Grumpy Programmer - 3 hour workshopchartjes
 
Tackling Testing Telephony
Tackling Testing Telephony Tackling Testing Telephony
Tackling Testing Telephony Mojo Lingo
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean CodingMetin Ogurlu
 
Completely Test-Driven
Completely Test-DrivenCompletely Test-Driven
Completely Test-DrivenIan Truslove
 
WTF TDD?
WTF TDD?WTF TDD?
WTF TDD?jeremyw
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best PracticesTomaš Maconko
 
Developer testing 201: When to Mock and When to Integrate
Developer testing 201: When to Mock and When to IntegrateDeveloper testing 201: When to Mock and When to Integrate
Developer testing 201: When to Mock and When to IntegrateLB Denker
 
Testing with laravel
Testing with laravelTesting with laravel
Testing with laravelDerek Binkley
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWJest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWHolger Grosse-Plankermann
 
What rails taught me – Eugene Pirogov
What rails taught me – Eugene PirogovWhat rails taught me – Eugene Pirogov
What rails taught me – Eugene PirogovRuby Meditation
 
The Cowardly Test-o-Phobe's Guide To Testing
The Cowardly Test-o-Phobe's Guide To TestingThe Cowardly Test-o-Phobe's Guide To Testing
The Cowardly Test-o-Phobe's Guide To TestingTim Duckett
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Danny Preussler
 
Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010ssoroka
 
Bigger Unit Test Are Better
Bigger Unit Test Are BetterBigger Unit Test Are Better
Bigger Unit Test Are BetterPeter Schuler
 
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...Mozaic Works
 
Testing sad-paths
Testing sad-pathsTesting sad-paths
Testing sad-pathsSolano Labs
 

Similar a Testing gone-right (20)

Learn To Test Like A Grumpy Programmer - 3 hour workshop
Learn To Test Like A Grumpy Programmer - 3 hour workshopLearn To Test Like A Grumpy Programmer - 3 hour workshop
Learn To Test Like A Grumpy Programmer - 3 hour workshop
 
Tackling Testing Telephony
Tackling Testing Telephony Tackling Testing Telephony
Tackling Testing Telephony
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean Coding
 
Completely Test-Driven
Completely Test-DrivenCompletely Test-Driven
Completely Test-Driven
 
WTF TDD?
WTF TDD?WTF TDD?
WTF TDD?
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best Practices
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
 
Rails traps
Rails trapsRails traps
Rails traps
 
Developer testing 201: When to Mock and When to Integrate
Developer testing 201: When to Mock and When to IntegrateDeveloper testing 201: When to Mock and When to Integrate
Developer testing 201: When to Mock and When to Integrate
 
Testing with laravel
Testing with laravelTesting with laravel
Testing with laravel
 
Clean code
Clean codeClean code
Clean code
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWJest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRW
 
Ruby basics
Ruby basicsRuby basics
Ruby basics
 
What rails taught me – Eugene Pirogov
What rails taught me – Eugene PirogovWhat rails taught me – Eugene Pirogov
What rails taught me – Eugene Pirogov
 
The Cowardly Test-o-Phobe's Guide To Testing
The Cowardly Test-o-Phobe's Guide To TestingThe Cowardly Test-o-Phobe's Guide To Testing
The Cowardly Test-o-Phobe's Guide To Testing
 
Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)
 
Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010
 
Bigger Unit Test Are Better
Bigger Unit Test Are BetterBigger Unit Test Are Better
Bigger Unit Test Are Better
 
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
 
Testing sad-paths
Testing sad-pathsTesting sad-paths
Testing sad-paths
 

Último

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 

Último (20)

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 

Testing gone-right

  • 1. Testing Gone Right from RubyConf 2011 and others @jwo - Jesse Wolgamott
  • 3. What We’ll Talk Abouts • Mock is not a 4 letter word • Fast tests. Really Fast. • Rails Models
  • 4. Mock is not a 4 letter word
  • 7. Mocks • Mocks are not stubs • Mocks assert Messages
  • 8. Mocks • Mocks are not stubs • Mocks assert Messages • Assert on state => Stubbing
  • 9. Mocks • Mocks are not stubs • Mocks assert Messages • Assert on state => Stubbing • Assert on messages => Mocking
  • 10. Ruby + OOP + Mock
  • 11. Ruby + OOP + Mock • is goood
  • 12. Ruby + OOP + Mock • is goood • Objects should tell objects to do things
  • 13. Ruby + OOP + Mock • is goood • Objects should tell objects to do things • (Tell don’t ask)
  • 14. Ruby + OOP + Mock • is goood • Objects should tell objects to do things • (Tell don’t ask) • You tell to do things using messages
  • 15. Mock Roles • Instead of mocking objects, try to mock roles • Wanting to mock concrete objects is a design smell
  • 17. Example • Restaurant system reserves tables • Instead of your interface talking to a ReservationService: • Talk to ReservationInterfaceHandler
  • 18. Message Example class ReservationInterface def initialize(handler) @handler = handler end def select_table(table) @table = table end def submit_request @handler.reserve(@table) end end
  • 19. And to Spec it describe ReservationInterface do let(:table){something_interesting_here} it "should tell the handler to reserve a table" do handler = double('reservation_handler') handler.should_receive(:reserve).with(table) machine = ReservationInterface.new(handler) machine.select_table(table) machine.submit_request end
  • 21. On APIs • Only Mock Types you own • Don’t mock boundary objects • If you do, you’ll duplicate code -> CODE SMELL
  • 23. Other Mock Smells • Having to setup more than 3 lines -- that’s a code smell
  • 24. Other Mock Smells • Having to setup more than 3 lines -- that’s a code smell • Mocking concrete objects -- that’s a code smell
  • 25. Other Mock Smells • Having to setup more than 3 lines -- that’s a code smell • Mocking concrete objects -- that’s a code smell • When tests go brittle and developers declare mocks suck -- that’s a code smell
  • 27. However • If you have a “standard” Rails app, programmed procedurally:
  • 28. However • If you have a “standard” Rails app, programmed procedurally: • Mocks are not for you
  • 29. However • If you have a “standard” Rails app, programmed procedurally: • Mocks are not for you • If you encapulate your code. If you hide information (OOP). If you use messages:
  • 30. However • If you have a “standard” Rails app, programmed procedurally: • Mocks are not for you • If you encapulate your code. If you hide information (OOP). If you use messages: • Mocks are for you!
  • 32. Mocks Don’t Suck • If your code is hard to test, you need better code
  • 33. Mocks Don’t Suck • If your code is hard to test, you need better code • If you have a test that is HARD to setup, your class (or test) is doing too much
  • 34. Mocks Don’t Suck • If your code is hard to test, you need better code • If you have a test that is HARD to setup, your class (or test) is doing too much • If you see tests with uber-mocks, the answer is not to delete mocks. It’s to isolate your tests
  • 36. Out of the Box
  • 37. Out of the Box • Most Rails apps start as CRUD apps
  • 38. Out of the Box • Most Rails apps start as CRUD apps • Tests start fast-ish
  • 39. Out of the Box • Most Rails apps start as CRUD apps • Tests start fast-ish • Like a frog, we don’t notice the increase
  • 40. “fast” tests • Tests should run in under a second • The entire rspec test suite
  • 42. Example Spec Run Real Time Time With Rails .07 s 8.1 s Without 0.0007 s .8 s Rails
  • 44. Avoid Factories • Instead, extract your code to classes with one single responsibility
  • 45. Avoid Factories • Instead, extract your code to classes with one single responsibility • Rather than knowing everything about your object
  • 46. Avoid Factories • Instead, extract your code to classes with one single responsibility • Rather than knowing everything about your object • Or, load methods via modules
  • 49. Rails Models • Are Fat. • Wait, isn’t that good?
  • 50. Rails Models • Are Fat. • Wait, isn’t that good? • It’s better than controller logic
  • 51. Rails Models • Are Fat. • Wait, isn’t that good? • It’s better than controller logic • But no.
  • 53. What then? • Your models can have validations
  • 54. What then? • Your models can have validations • Call out to policy or decision classes for business logic
  • 55. What then? • Your models can have validations • Call out to policy or decision classes for business logic • Use Ruby Classes
  • 56. What then? • Your models can have validations • Call out to policy or decision classes for business logic • Use Ruby Classes • Use Presenters
  • 57. Example • Example of building a burrito that is delicious, and can know it’s delicious • In Isolation: https://gist.github.com/1281093 • Using Modules: https://gist.github.com/ 1281064
  • 58. Credits Why you don’t get mock objects @gregmoeck Your tests are lying to you @chrismdp Fast Rails talk at gogoruco 2011 @coreyhaines Testing in Isolation. @garybernhardt destroyalldoftware.com

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n