SlideShare une entreprise Scribd logo
1  sur  17
Best practices for writing
                 automated tests




     Felipe Lima
felipe@gogobot.com
      @felipecsl
• Assumption 1: You are already
 convinced that automated tests are
 good
• Assumption II: You agree that best
 way to accomplish that is writing
 tests before you code.
What is considered to be a
        good test?
Structure - AAA:


• Arrange
• Act
• Assert
What makes a good test?
• Assumes a clean environment (empty
 database, redis, solr, etc.)

• Cleans up after itself
• Runs quickly
• Readable, simple to understand
• Tests only one thing at a time
• Isolates the class you are testing
• Stubs external dependencies (eg.: vcr)
• Thorough: covers happy and edge cases
• Repeatable: always provides same results
• Doesn’t make unnecessary assertions
• Clearly and consistently named
SOLID

• Single Responsibility Principle
• Open/closed principle
• Liskov substitution principle
• Interface segregation principle
• Dependancy Inversion principle
Why write tests before the code?
• SOLID code is HIGHLY testable
• TDD forces you to think about your
 design

• Bad code is hard to test
• It is a design process, not a testing process
“TDD is a robust way of designing
software components (“units”)
interactively so that their behaviour is
specified through unit tests.”




 http://blog.stevensanderson.com/2009/08/24/writing-great-unit-tests-best-and-worst-practises/
http://blog.stevensanderson.com/2009/08/24/writing-great-unit-tests-best-and-worst-practises/
TDD Mantra:

Red => Green => Refactor




http://www.agileapps.co.uk/methodology/continuous.html
Mocks and Stubs:

• Mocks set up expectations on messages that
 are passed between objects

• Stubs provide canned answers to calls made
 during the test

• Only mocks specify expected behavior and
 make assertions

• Also know as test doubles (eg.: in RSpec)

       Reference: http://martinfowler.com/articles/mocksArentStubs.html
Stub example:

controller.stub(:current_user).and_return(fake_user)




Mock example:
user.should_receive(:postcards).and_return([p1, p2, p3])
postcards = controller.postcards(user.id)
postcards.should =~ [p1, p2, p3]

Contenu connexe

Tendances

Testing Frameworks And Methodologies
Testing Frameworks And MethodologiesTesting Frameworks And Methodologies
Testing Frameworks And Methodologies
Steven Cahill
 
Testing Design System Changes Across Your Application -- Intuit Use Case -- w...
Testing Design System Changes Across Your Application -- Intuit Use Case -- w...Testing Design System Changes Across Your Application -- Intuit Use Case -- w...
Testing Design System Changes Across Your Application -- Intuit Use Case -- w...
Applitools
 

Tendances (20)

Testing automation in agile environment
Testing automation in agile environmentTesting automation in agile environment
Testing automation in agile environment
 
Framework for Web Automation Testing
Framework for Web Automation TestingFramework for Web Automation Testing
Framework for Web Automation Testing
 
Why Automated Testing Matters To DevOps
Why Automated Testing Matters To DevOpsWhy Automated Testing Matters To DevOps
Why Automated Testing Matters To DevOps
 
Elements of a Test Framework
Elements of a Test FrameworkElements of a Test Framework
Elements of a Test Framework
 
Automated vs manual testing
Automated vs manual testingAutomated vs manual testing
Automated vs manual testing
 
Creating Maintainable Automated Acceptance Tests
Creating Maintainable Automated Acceptance TestsCreating Maintainable Automated Acceptance Tests
Creating Maintainable Automated Acceptance Tests
 
Eclipse UI automation
Eclipse UI automationEclipse UI automation
Eclipse UI automation
 
Red7 Automating UAT Web Testing
Red7 Automating UAT Web TestingRed7 Automating UAT Web Testing
Red7 Automating UAT Web Testing
 
How to Add Test Automation to your Quality Assurance Toolbelt
How to Add Test Automation to your Quality Assurance ToolbeltHow to Add Test Automation to your Quality Assurance Toolbelt
How to Add Test Automation to your Quality Assurance Toolbelt
 
Testing Frameworks And Methodologies
Testing Frameworks And MethodologiesTesting Frameworks And Methodologies
Testing Frameworks And Methodologies
 
Software testing
Software testingSoftware testing
Software testing
 
Software testing and quality assurance
Software testing and quality assuranceSoftware testing and quality assurance
Software testing and quality assurance
 
Quality Assurance Guidelines
Quality Assurance GuidelinesQuality Assurance Guidelines
Quality Assurance Guidelines
 
Career in Software Testing | Skills Required for Software Test Engineer | Edu...
Career in Software Testing | Skills Required for Software Test Engineer | Edu...Career in Software Testing | Skills Required for Software Test Engineer | Edu...
Career in Software Testing | Skills Required for Software Test Engineer | Edu...
 
Test team dynamics, Антон Мужайло
Test team dynamics, Антон МужайлоTest team dynamics, Антон Мужайло
Test team dynamics, Антон Мужайло
 
Test Automation failure analysis
Test Automation failure analysisTest Automation failure analysis
Test Automation failure analysis
 
Functional & Performance Test Automation with CI
Functional & Performance Test Automation with CI Functional & Performance Test Automation with CI
Functional & Performance Test Automation with CI
 
Sustainable agile testing
Sustainable agile testingSustainable agile testing
Sustainable agile testing
 
Test Automation
Test AutomationTest Automation
Test Automation
 
Testing Design System Changes Across Your Application -- Intuit Use Case -- w...
Testing Design System Changes Across Your Application -- Intuit Use Case -- w...Testing Design System Changes Across Your Application -- Intuit Use Case -- w...
Testing Design System Changes Across Your Application -- Intuit Use Case -- w...
 

En vedette

How to Design a Successful Test Automation Strategy
How to Design a Successful Test Automation Strategy How to Design a Successful Test Automation Strategy
How to Design a Successful Test Automation Strategy
Impetus Technologies
 
Automation testing strategy, approach & planning
Automation testing  strategy, approach & planningAutomation testing  strategy, approach & planning
Automation testing strategy, approach & planning
SivaprasanthRentala1975
 
Automating good coding practices
Automating good coding practicesAutomating good coding practices
Automating good coding practices
Kevin Peterson
 

En vedette (12)

How to Design a Successful Test Automation Strategy
How to Design a Successful Test Automation Strategy How to Design a Successful Test Automation Strategy
How to Design a Successful Test Automation Strategy
 
Automation testing strategy, approach & planning
Automation testing  strategy, approach & planningAutomation testing  strategy, approach & planning
Automation testing strategy, approach & planning
 
Test Automation Framework Designs
Test Automation Framework DesignsTest Automation Framework Designs
Test Automation Framework Designs
 
Automating good coding practices
Automating good coding practicesAutomating good coding practices
Automating good coding practices
 
Best Practises In Test Automation
Best Practises In Test AutomationBest Practises In Test Automation
Best Practises In Test Automation
 
Elemente de radiologie pentru rezidenti
Elemente de radiologie pentru rezidentiElemente de radiologie pentru rezidenti
Elemente de radiologie pentru rezidenti
 
AAA Automated Testing
AAA Automated TestingAAA Automated Testing
AAA Automated Testing
 
Automation test scripting techniques
Automation test scripting techniquesAutomation test scripting techniques
Automation test scripting techniques
 
Elemente de radiologie toracică pentru rezidenţi
Elemente de radiologie toracică pentru rezidenţiElemente de radiologie toracică pentru rezidenţi
Elemente de radiologie toracică pentru rezidenţi
 
Test Automation Best Practices (with SOA test approach)
Test Automation Best Practices (with SOA test approach)Test Automation Best Practices (with SOA test approach)
Test Automation Best Practices (with SOA test approach)
 
BDD - Writing better scenario
BDD - Writing better scenarioBDD - Writing better scenario
BDD - Writing better scenario
 
Test Automation Strategies For Agile
Test Automation Strategies For AgileTest Automation Strategies For Agile
Test Automation Strategies For Agile
 

Similaire à Best practices for writing good automated tests

Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
Meilan Ou
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolator
MaslowB
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best Practices
Tomaš Maconko
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolator
MaslowB
 
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Ortus Solutions, Corp
 

Similaire à Best practices for writing good automated tests (20)

CNUG TDD June 2014
CNUG TDD June 2014CNUG TDD June 2014
CNUG TDD June 2014
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolator
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best Practices
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolator
 
Testing with laravel
Testing with laravelTesting with laravel
Testing with laravel
 
Writing Better Tests - Applying Clean-Code TDD at 99designs
Writing Better Tests - Applying Clean-Code TDD at 99designsWriting Better Tests - Applying Clean-Code TDD at 99designs
Writing Better Tests - Applying Clean-Code TDD at 99designs
 
A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven Development
 
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
 
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
 
Unit Testing and Tools
Unit Testing and ToolsUnit Testing and Tools
Unit Testing and Tools
 
Clean tests
Clean testsClean tests
Clean tests
 
TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)
 
Clean Code Talk (draft)
Clean Code Talk (draft)Clean Code Talk (draft)
Clean Code Talk (draft)
 
Clean code
Clean codeClean code
Clean code
 
Unit Testing talk
Unit Testing talkUnit Testing talk
Unit Testing talk
 
How to write test in node.js
How to write test in node.jsHow to write test in node.js
How to write test in node.js
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
 
Eurosport's Kodakademi #2
Eurosport's Kodakademi #2Eurosport's Kodakademi #2
Eurosport's Kodakademi #2
 

Best practices for writing good automated tests

Notes de l'éditeur

  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