SlideShare a Scribd company logo
1 of 24
Download to read offline
The Future Is Now:
Writing Automated Tests
To Grow Your Code
Isaac Murchie, Ecosystem and Integrations Developer
Sauce Labs
Why test?
http://www.history.navy.mil/photos/images/h96000/h96566kc.htm
Types of tests
• Unit tests - testing individual software
components or modules. Tests module API,
not internals.
• Integration tests - testing of integrated
modules to verify combined functionality.
• Functional / GUI tests - testing of functionality
to make sure it works as required (also
System, End-to-End, etc.).
• Load, Stress, Performance, Usability,
Acceptance tests, etc.
Unit tests
• White-box tests of individual units.
• Isolate each part of the program and show that the
individual parts are correct.
• Should test functions isolated from their interaction with
other parts and from I/O.
• Substitute interacting parts with method stubs, mock
objects, and fakes.
• Separation of interface from implementation.
• Benefits
• Find problems early.
• Allow for safer refactoring.
• Simplify integration.
• Can drive the design of more modular, reusable
software.
def add(a, b):	
return a + b	
!
def test_add():	
assert add(4, 5) == 9
Simple assertions
Assertions on errors
def divide_by_zero(a):	
a / 0	
!
def test_zero_division():	
with pytest.raises(ZeroDivisionError) as einfo:	
divide_by_zero(3)	
!
assert 'exceptions.ZeroDivisionError' in str(einfo.type)	
assert 'by zero' in str(einfo.value)
import datetime	
from django.utils import timezone	
!
from polls.models import Poll	
!
!
class TestPollMethod(object):	
def test_was_published_recently_with_future_poll(self):	
"""	
was_published_recently() should return False for 	
polls whose pub_date is in the future	
"""	
future_poll = Poll(pub_date=timezone.now() +	
datetime.timedelta(days=30))	
assert future_poll.was_published_recently() == False
Integration tests
• Individual modules are combined and tested as a
group.
• Verifies functional, performance, and reliability
requirements placed on larger units of the software.
• Tests communication between modules.
• May still involve mocking out certain services.
import datetime	
from django.core.urlresolvers import reverse	
from django.utils import timezone	
!
from polls.models import Poll	
!
@pytest.mark.django_db	
class TestPollView(object):	
def test_index_view_with_a_past_poll(self, client):	
"""	
Polls with a pub_date in the past should be displayed on 	
the index page.	
"""	
create_poll(question="Past poll.", days=-30)	
response = client.get(reverse('polls:index'))	
!
assert 'Past poll.' == 	
response.context['latest_poll_list'][0].question
Functional tests
• Black-box tests of a portion of the software.
• Tests what the program does, not how it does it.
• Verifies a program against its specification and
requirements.
• Slow.
• Brittle.
import unittest	
from selenium import webdriver	
!
class TestPollSelenium(unittest.TestCase):	
def setUp(self):	
self.driver = webdriver.Remote(	
desired_capabilities = {	
'platform': 'MAC',	
'browserName': 'chrome',	
'version': '38'	
},	
command_executor = 'http://localhost:4444/wd/hub'	
)	
!
def tearDown(self):	
self.driver.quit()	
!
def test_poll_index(self):	
self.driver.get('http://localhost:8000/polls/')	
assert 'Poll Index' in self.driver.title	
!
el = self.driver.find_element_by_link_text('What's up?')	
assert el != None
Originally from Succeeding with Agile, Mike Cohn 2009.
Test early and test often.
Which is to say,
Regression testing
"As a consequence of the introduction of new bugs, program
maintenance requires far more system testing per statement written
than any other programming. Theoretically, after each fix one must
run the entire bank of test cases previously run against the system,
to ensure that it has not been damaged in an obscure way. In
practice, such regression testing must indeed approximate this
theoretical ideal, and it is very costly."
The Mythical Man-Month, Frederick P. Brooks, Jr., 1974, 122.
• Can be at any level of testing.
• Test for regressions, re-emergence of old faults, as
well the emergence of new ones.
• Most easily done through use of Continuous
Integration systems.
Continuous Integration
• Merging working copies of code in short intervals.
• Coupled with automated running of automated tests.
• Use of dedicated build environment.
def add(a, b):	
return a + b	
!
def test_add():	
assert add(4, 5) == 9
Simple assertions
Assertions on errors
def divide_by_zero(a):	
a / 0	
!
def test_zero_division():	
with pytest.raises(ZeroDivisionError) as einfo:	
divide_by_zero(3)	
!
assert 'exceptions.ZeroDivisionError' in str(einfo.type)	
assert 'by zero' in str(einfo.value)
Testing Django apps
import datetime	
from django.utils import timezone	
!
from polls.models import Poll	
!
!
class TestPollMethod(object):	
def test_was_published_recently_with_future_poll(self):	
"""	
was_published_recently() should return False for 	
polls whose pub_date is in the future	
"""	
future_poll = Poll(pub_date=timezone.now() +	
datetime.timedelta(days=30))	
assert future_poll.was_published_recently() == False
import datetime	
from django.core.urlresolvers import reverse	
from django.utils import timezone	
!
from polls.models import Poll	
!
@pytest.mark.django_db	
class TestPollView(object):	
def test_index_view_with_a_past_poll(self, client):	
"""	
Polls with a pub_date in the past should be displayed on 	
the index page.	
"""	
create_poll(question="Past poll.", days=-30)	
response = client.get(reverse('polls:index'))	
!
assert 'Past poll.' == 	
response.context['latest_poll_list'][0].question
import unittest	
from selenium import webdriver	
!
class TestPollSelenium(unittest.TestCase):	
def setUp(self):	
self.driver = webdriver.Remote(	
desired_capabilities = {	
'platform': 'MAC',	
'browserName': 'chrome',	
'version': '38'	
},	
command_executor = 'http://localhost:4444/wd/hub'	
)	
!
def tearDown(self):	
self.driver.quit()	
!
def test_poll_index(self):	
self.driver.get('http://localhost:8000/polls/')	
assert 'Poll Index' in self.driver.title	
!
el = self.driver.find_element_by_link_text('What's up?')	
assert el != None
isaac@saucelabs.com
https://github.com/imurchie

More Related Content

What's hot

An Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitAn Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitweili_at_slideshare
 
Unit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveUnit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveAlvaro Videla
 
Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.Deepak Singhvi
 
Test driven development
Test driven developmentTest driven development
Test driven developmentlukaszkujawa
 
Unit testing with NUnit
Unit testing with NUnitUnit testing with NUnit
Unit testing with NUnitkleinron
 
Benefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real WorldBenefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real WorldDror Helper
 
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...Thomas Weller
 
Embrace Unit Testing
Embrace Unit TestingEmbrace Unit Testing
Embrace Unit Testingalessiopace
 
Agile Acceptance testing with Fitnesse
Agile Acceptance testing with FitnesseAgile Acceptance testing with Fitnesse
Agile Acceptance testing with FitnesseClareMcLennan
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven DevelopmentPablo Villar
 
Tdd Ugialtnet Jan2010
Tdd Ugialtnet Jan2010Tdd Ugialtnet Jan2010
Tdd Ugialtnet Jan2010guestcff805
 
Software testing lab 7 & 8
Software testing lab 7 & 8Software testing lab 7 & 8
Software testing lab 7 & 8AfrasiabKhan21
 
Unit & integration testing
Unit & integration testingUnit & integration testing
Unit & integration testingPavlo Hodysh
 
Qtp Basics
Qtp BasicsQtp Basics
Qtp Basicsmehramit
 
Unit Tests And Automated Testing
Unit Tests And Automated TestingUnit Tests And Automated Testing
Unit Tests And Automated TestingLee Englestone
 
Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Hong Le Van
 

What's hot (20)

An Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitAn Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnit
 
Unit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveUnit Test + Functional Programming = Love
Unit Test + Functional Programming = Love
 
Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Unit testing with NUnit
Unit testing with NUnitUnit testing with NUnit
Unit testing with NUnit
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Benefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real WorldBenefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real World
 
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
 
Embrace Unit Testing
Embrace Unit TestingEmbrace Unit Testing
Embrace Unit Testing
 
Unit testing
Unit testingUnit testing
Unit testing
 
Agile Acceptance testing with Fitnesse
Agile Acceptance testing with FitnesseAgile Acceptance testing with Fitnesse
Agile Acceptance testing with Fitnesse
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Tdd Ugialtnet Jan2010
Tdd Ugialtnet Jan2010Tdd Ugialtnet Jan2010
Tdd Ugialtnet Jan2010
 
Software testing lab 7 & 8
Software testing lab 7 & 8Software testing lab 7 & 8
Software testing lab 7 & 8
 
Unit & integration testing
Unit & integration testingUnit & integration testing
Unit & integration testing
 
Qtp Basics
Qtp BasicsQtp Basics
Qtp Basics
 
Unit Tests And Automated Testing
Unit Tests And Automated TestingUnit Tests And Automated Testing
Unit Tests And Automated Testing
 
Testing in TFS
Testing in TFSTesting in TFS
Testing in TFS
 
Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++
 

Viewers also liked

The pizza goes to the Oscars
The pizza goes to the OscarsThe pizza goes to the Oscars
The pizza goes to the Oscarsconnectingdots
 
Diary of a single woman in her 30s! (oh damn!)
Diary of a single woman in her 30s! (oh damn!)Diary of a single woman in her 30s! (oh damn!)
Diary of a single woman in her 30s! (oh damn!)connectingdots
 
Appium for RubyMotion
Appium for RubyMotionAppium for RubyMotion
Appium for RubyMotionIsaac Murchie
 
National health policy draft 2015
National health policy draft 2015National health policy draft 2015
National health policy draft 2015Partha Sarathi Ain
 
Regional understanding via travel based ethnography
Regional understanding via travel based ethnography Regional understanding via travel based ethnography
Regional understanding via travel based ethnography connectingdots
 
Kolkata Bengali...udi baba, uff, ishh
Kolkata Bengali...udi baba, uff, ishhKolkata Bengali...udi baba, uff, ishh
Kolkata Bengali...udi baba, uff, ishhconnectingdots
 
Improving Android app testing with Appium and Sauce Labs
Improving Android app testing with Appium and Sauce LabsImproving Android app testing with Appium and Sauce Labs
Improving Android app testing with Appium and Sauce LabsIsaac Murchie
 
Moderating conversations with millennial target groups
Moderating conversations with millennial target groupsModerating conversations with millennial target groups
Moderating conversations with millennial target groupsconnectingdots
 
What your mother did not tell you Qualitative Research can!
What your mother did not tell you Qualitative Research can!What your mother did not tell you Qualitative Research can!
What your mother did not tell you Qualitative Research can!connectingdots
 
Decoding taglines for Kaun Banega Crorepati (Who Wants to be a Millionaire) I...
Decoding taglines for Kaun Banega Crorepati (Who Wants to be a Millionaire) I...Decoding taglines for Kaun Banega Crorepati (Who Wants to be a Millionaire) I...
Decoding taglines for Kaun Banega Crorepati (Who Wants to be a Millionaire) I...connectingdots
 

Viewers also liked (13)

The pizza goes to the Oscars
The pizza goes to the OscarsThe pizza goes to the Oscars
The pizza goes to the Oscars
 
Diary of a single woman in her 30s! (oh damn!)
Diary of a single woman in her 30s! (oh damn!)Diary of a single woman in her 30s! (oh damn!)
Diary of a single woman in her 30s! (oh damn!)
 
Appium for RubyMotion
Appium for RubyMotionAppium for RubyMotion
Appium for RubyMotion
 
National health policy draft 2015
National health policy draft 2015National health policy draft 2015
National health policy draft 2015
 
Gastro lactose
Gastro lactoseGastro lactose
Gastro lactose
 
Regional understanding via travel based ethnography
Regional understanding via travel based ethnography Regional understanding via travel based ethnography
Regional understanding via travel based ethnography
 
Appium 1.0
Appium 1.0Appium 1.0
Appium 1.0
 
Kolkata Bengali...udi baba, uff, ishh
Kolkata Bengali...udi baba, uff, ishhKolkata Bengali...udi baba, uff, ishh
Kolkata Bengali...udi baba, uff, ishh
 
Improving Android app testing with Appium and Sauce Labs
Improving Android app testing with Appium and Sauce LabsImproving Android app testing with Appium and Sauce Labs
Improving Android app testing with Appium and Sauce Labs
 
Histology study guide
Histology study guideHistology study guide
Histology study guide
 
Moderating conversations with millennial target groups
Moderating conversations with millennial target groupsModerating conversations with millennial target groups
Moderating conversations with millennial target groups
 
What your mother did not tell you Qualitative Research can!
What your mother did not tell you Qualitative Research can!What your mother did not tell you Qualitative Research can!
What your mother did not tell you Qualitative Research can!
 
Decoding taglines for Kaun Banega Crorepati (Who Wants to be a Millionaire) I...
Decoding taglines for Kaun Banega Crorepati (Who Wants to be a Millionaire) I...Decoding taglines for Kaun Banega Crorepati (Who Wants to be a Millionaire) I...
Decoding taglines for Kaun Banega Crorepati (Who Wants to be a Millionaire) I...
 

Similar to The Future is Now: Writing Automated Tests To Grow Your Code

Software testing: an introduction - 2017
Software testing: an introduction - 2017Software testing: an introduction - 2017
Software testing: an introduction - 2017XavierDevroey
 
Coldbox developer training – session 4
Coldbox developer training – session 4Coldbox developer training – session 4
Coldbox developer training – session 4Billie Berzinskas
 
Lecture (Software Testing).pptx
Lecture (Software Testing).pptxLecture (Software Testing).pptx
Lecture (Software Testing).pptxskknowledge
 
Beginners overview of automated testing with Rspec
Beginners overview of automated testing with RspecBeginners overview of automated testing with Rspec
Beginners overview of automated testing with Rspecjeffrey1ross
 
Unit testing and mocking in Python - PyCon 2018 - Kenya
Unit testing and mocking in Python - PyCon 2018 - KenyaUnit testing and mocking in Python - PyCon 2018 - Kenya
Unit testing and mocking in Python - PyCon 2018 - KenyaErick M'bwana
 
Integration and Unit Testing in Java using Test Doubles like mocks and stubs
Integration and Unit Testing in Java using Test Doubles like mocks and stubsIntegration and Unit Testing in Java using Test Doubles like mocks and stubs
Integration and Unit Testing in Java using Test Doubles like mocks and stubsRody Middelkoop
 
Никита Галкин "Testing in Frontend World"
Никита Галкин "Testing in Frontend World"Никита Галкин "Testing in Frontend World"
Никита Галкин "Testing in Frontend World"Fwdays
 
OOSE Unit 5 PPT.ppt
OOSE Unit 5 PPT.pptOOSE Unit 5 PPT.ppt
OOSE Unit 5 PPT.pptitadmin33
 
Dependency Injection in .NET applications
Dependency Injection in .NET applicationsDependency Injection in .NET applications
Dependency Injection in .NET applicationsBabak Naffas
 
Oose unit 5 ppt
Oose unit 5 pptOose unit 5 ppt
Oose unit 5 pptDr VISU P
 
Testing terms & definitions
Testing terms & definitionsTesting terms & definitions
Testing terms & definitionsSachin MK
 
unit test in node js - test cases in node
unit test in node js - test cases in nodeunit test in node js - test cases in node
unit test in node js - test cases in nodeGoa App
 
Software testing
Software testingSoftware testing
Software testingEng Ibrahem
 
Into The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applicationsInto The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applicationsOrtus Solutions, Corp
 

Similar to The Future is Now: Writing Automated Tests To Grow Your Code (20)

Software testing: an introduction - 2017
Software testing: an introduction - 2017Software testing: an introduction - 2017
Software testing: an introduction - 2017
 
Coldbox developer training – session 4
Coldbox developer training – session 4Coldbox developer training – session 4
Coldbox developer training – session 4
 
Testing Angular
Testing AngularTesting Angular
Testing Angular
 
Lecture (Software Testing).pptx
Lecture (Software Testing).pptxLecture (Software Testing).pptx
Lecture (Software Testing).pptx
 
Beginners overview of automated testing with Rspec
Beginners overview of automated testing with RspecBeginners overview of automated testing with Rspec
Beginners overview of automated testing with Rspec
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
Unit testing and mocking in Python - PyCon 2018 - Kenya
Unit testing and mocking in Python - PyCon 2018 - KenyaUnit testing and mocking in Python - PyCon 2018 - Kenya
Unit testing and mocking in Python - PyCon 2018 - Kenya
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Integration and Unit Testing in Java using Test Doubles like mocks and stubs
Integration and Unit Testing in Java using Test Doubles like mocks and stubsIntegration and Unit Testing in Java using Test Doubles like mocks and stubs
Integration and Unit Testing in Java using Test Doubles like mocks and stubs
 
Unit testing
Unit testingUnit testing
Unit testing
 
Никита Галкин "Testing in Frontend World"
Никита Галкин "Testing in Frontend World"Никита Галкин "Testing in Frontend World"
Никита Галкин "Testing in Frontend World"
 
OOSE Unit 5 PPT.ppt
OOSE Unit 5 PPT.pptOOSE Unit 5 PPT.ppt
OOSE Unit 5 PPT.ppt
 
Dependency Injection in .NET applications
Dependency Injection in .NET applicationsDependency Injection in .NET applications
Dependency Injection in .NET applications
 
Oose unit 5 ppt
Oose unit 5 pptOose unit 5 ppt
Oose unit 5 ppt
 
Testing terms & definitions
Testing terms & definitionsTesting terms & definitions
Testing terms & definitions
 
unit test in node js - test cases in node
unit test in node js - test cases in nodeunit test in node js - test cases in node
unit test in node js - test cases in node
 
Software testing
Software testingSoftware testing
Software testing
 
Into The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applicationsInto The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applications
 
Lecture 21
Lecture 21Lecture 21
Lecture 21
 
Grails Spock Testing
Grails Spock TestingGrails Spock Testing
Grails Spock Testing
 

Recently uploaded

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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
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
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
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
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
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
 
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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Recently uploaded (20)

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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
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...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
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
 
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...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

The Future is Now: Writing Automated Tests To Grow Your Code

  • 1. The Future Is Now: Writing Automated Tests To Grow Your Code Isaac Murchie, Ecosystem and Integrations Developer Sauce Labs
  • 4. Types of tests • Unit tests - testing individual software components or modules. Tests module API, not internals. • Integration tests - testing of integrated modules to verify combined functionality. • Functional / GUI tests - testing of functionality to make sure it works as required (also System, End-to-End, etc.). • Load, Stress, Performance, Usability, Acceptance tests, etc.
  • 5. Unit tests • White-box tests of individual units. • Isolate each part of the program and show that the individual parts are correct. • Should test functions isolated from their interaction with other parts and from I/O. • Substitute interacting parts with method stubs, mock objects, and fakes. • Separation of interface from implementation. • Benefits • Find problems early. • Allow for safer refactoring. • Simplify integration. • Can drive the design of more modular, reusable software.
  • 6. def add(a, b): return a + b ! def test_add(): assert add(4, 5) == 9 Simple assertions
  • 7. Assertions on errors def divide_by_zero(a): a / 0 ! def test_zero_division(): with pytest.raises(ZeroDivisionError) as einfo: divide_by_zero(3) ! assert 'exceptions.ZeroDivisionError' in str(einfo.type) assert 'by zero' in str(einfo.value)
  • 8. import datetime from django.utils import timezone ! from polls.models import Poll ! ! class TestPollMethod(object): def test_was_published_recently_with_future_poll(self): """ was_published_recently() should return False for polls whose pub_date is in the future """ future_poll = Poll(pub_date=timezone.now() + datetime.timedelta(days=30)) assert future_poll.was_published_recently() == False
  • 9. Integration tests • Individual modules are combined and tested as a group. • Verifies functional, performance, and reliability requirements placed on larger units of the software. • Tests communication between modules. • May still involve mocking out certain services.
  • 10. import datetime from django.core.urlresolvers import reverse from django.utils import timezone ! from polls.models import Poll ! @pytest.mark.django_db class TestPollView(object): def test_index_view_with_a_past_poll(self, client): """ Polls with a pub_date in the past should be displayed on the index page. """ create_poll(question="Past poll.", days=-30) response = client.get(reverse('polls:index')) ! assert 'Past poll.' == response.context['latest_poll_list'][0].question
  • 11. Functional tests • Black-box tests of a portion of the software. • Tests what the program does, not how it does it. • Verifies a program against its specification and requirements. • Slow. • Brittle.
  • 12. import unittest from selenium import webdriver ! class TestPollSelenium(unittest.TestCase): def setUp(self): self.driver = webdriver.Remote( desired_capabilities = { 'platform': 'MAC', 'browserName': 'chrome', 'version': '38' }, command_executor = 'http://localhost:4444/wd/hub' ) ! def tearDown(self): self.driver.quit() ! def test_poll_index(self): self.driver.get('http://localhost:8000/polls/') assert 'Poll Index' in self.driver.title ! el = self.driver.find_element_by_link_text('What's up?') assert el != None
  • 13. Originally from Succeeding with Agile, Mike Cohn 2009.
  • 14.
  • 15. Test early and test often. Which is to say,
  • 16. Regression testing "As a consequence of the introduction of new bugs, program maintenance requires far more system testing per statement written than any other programming. Theoretically, after each fix one must run the entire bank of test cases previously run against the system, to ensure that it has not been damaged in an obscure way. In practice, such regression testing must indeed approximate this theoretical ideal, and it is very costly." The Mythical Man-Month, Frederick P. Brooks, Jr., 1974, 122.
  • 17. • Can be at any level of testing. • Test for regressions, re-emergence of old faults, as well the emergence of new ones. • Most easily done through use of Continuous Integration systems.
  • 18. Continuous Integration • Merging working copies of code in short intervals. • Coupled with automated running of automated tests. • Use of dedicated build environment.
  • 19. def add(a, b): return a + b ! def test_add(): assert add(4, 5) == 9 Simple assertions
  • 20. Assertions on errors def divide_by_zero(a): a / 0 ! def test_zero_division(): with pytest.raises(ZeroDivisionError) as einfo: divide_by_zero(3) ! assert 'exceptions.ZeroDivisionError' in str(einfo.type) assert 'by zero' in str(einfo.value)
  • 21. Testing Django apps import datetime from django.utils import timezone ! from polls.models import Poll ! ! class TestPollMethod(object): def test_was_published_recently_with_future_poll(self): """ was_published_recently() should return False for polls whose pub_date is in the future """ future_poll = Poll(pub_date=timezone.now() + datetime.timedelta(days=30)) assert future_poll.was_published_recently() == False
  • 22. import datetime from django.core.urlresolvers import reverse from django.utils import timezone ! from polls.models import Poll ! @pytest.mark.django_db class TestPollView(object): def test_index_view_with_a_past_poll(self, client): """ Polls with a pub_date in the past should be displayed on the index page. """ create_poll(question="Past poll.", days=-30) response = client.get(reverse('polls:index')) ! assert 'Past poll.' == response.context['latest_poll_list'][0].question
  • 23. import unittest from selenium import webdriver ! class TestPollSelenium(unittest.TestCase): def setUp(self): self.driver = webdriver.Remote( desired_capabilities = { 'platform': 'MAC', 'browserName': 'chrome', 'version': '38' }, command_executor = 'http://localhost:4444/wd/hub' ) ! def tearDown(self): self.driver.quit() ! def test_poll_index(self): self.driver.get('http://localhost:8000/polls/') assert 'Poll Index' in self.driver.title ! el = self.driver.find_element_by_link_text('What's up?') assert el != None