SlideShare uma empresa 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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque

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
 

Destaque (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
 

Semelhante 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
 

Semelhante 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

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 

Último (20)

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 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 do 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