SlideShare uma empresa Scribd logo
1 de 9
Baixar para ler offline
Mock Testing mit Python
PyBonn Meetup – März 2013
Timo Stollenwerk
Testing Pyramide
Ein Test ist kein Unit Test wenn
●
    Datenbankverbindung
●
    Netzwerkverbindung
●
    Dateisystemzugriff
●
    Externer Service
Mocks in Python
●
    Mock
●
    Mocker
●
    pMock
●
    pyMock
●
    mox
●
    ...
PostMonkey
>>> from postmonkey import PostMonkey
>>> pm = PostMonkey('your_api_key')


>>> pm.ping()
u"Everything's Chimpy!"
Mocker
>>> mocker = Mocker()
>>> postmonkey = mocker.replace("postmonkey")
>>> pm = postmonkey.PostMonkey(ANY)


>>> pm.ping()
>>> mocker.result(u"Everything's Chimpy!")


>>> mocker.replay()
Mocker: PostMonkey
>>> from postmonkey import PostMonkey
>>> pm = PostMonkey('your_api_key')


>>> pm.ping()
u"Everything's Chimpy!"


>>> pm
<mocker.Mock object at 0x9d7624c>
Mock
>>> @patch('postmonkey.PostMonkey')
>>> def test_mailchimp_ping_method(mock_class):
>>>    mock_class().ping = MagicMock(
>>>        return_value=u"Everything's Chimpy!")
>>>    from postmonkey import PostMonkey
>>>    pm = PostMonkey('123')
>>>    assert pm.ping() == u"Everything's Chimpy!"


>>> test_mailchimp_ping_method()
Mock Testing mit Python
PyBonn Meetup – März 2013
Timo Stollenwerk




github.com/tisto/mock-testing-in-python

Mais conteúdo relacionado

Mais procurados

Making the most of your Test Suite
Making the most of your Test SuiteMaking the most of your Test Suite
Making the most of your Test Suite
ericholscher
 
Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrency
Cloudflare
 

Mais procurados (18)

RuntimeUnitTestToolkit for Unity(English)
RuntimeUnitTestToolkit for Unity(English)RuntimeUnitTestToolkit for Unity(English)
RuntimeUnitTestToolkit for Unity(English)
 
Migrating from drupal to plone with transmogrifier
Migrating from drupal to plone with transmogrifierMigrating from drupal to plone with transmogrifier
Migrating from drupal to plone with transmogrifier
 
Building Hermetic Systems (without Docker)
Building Hermetic Systems (without Docker)Building Hermetic Systems (without Docker)
Building Hermetic Systems (without Docker)
 
Functional Reactive Programming without Black Magic (UIKonf 2015)
Functional Reactive Programming without Black Magic (UIKonf 2015)Functional Reactive Programming without Black Magic (UIKonf 2015)
Functional Reactive Programming without Black Magic (UIKonf 2015)
 
Transmogrifier: Migrating to Plone with less pain
Transmogrifier: Migrating to Plone with less painTransmogrifier: Migrating to Plone with less pain
Transmogrifier: Migrating to Plone with less pain
 
Golang concurrency design
Golang concurrency designGolang concurrency design
Golang concurrency design
 
Golang design4concurrency
Golang design4concurrencyGolang design4concurrency
Golang design4concurrency
 
Understanding real world concurrency bugs in go (fixed)
Understanding real world concurrency bugs in go (fixed)Understanding real world concurrency bugs in go (fixed)
Understanding real world concurrency bugs in go (fixed)
 
Making the most of your Test Suite
Making the most of your Test SuiteMaking the most of your Test Suite
Making the most of your Test Suite
 
Stop js-1999
Stop js-1999Stop js-1999
Stop js-1999
 
Testing Django Applications
Testing Django ApplicationsTesting Django Applications
Testing Django Applications
 
Ruby Concurrency and EventMachine
Ruby Concurrency and EventMachineRuby Concurrency and EventMachine
Ruby Concurrency and EventMachine
 
Source Plugins
Source PluginsSource Plugins
Source Plugins
 
Understanding real world concurrency bugs in go
Understanding real world concurrency bugs in go Understanding real world concurrency bugs in go
Understanding real world concurrency bugs in go
 
Fxug@北陸in富山 - Flex Unit4Beta1+α -
Fxug@北陸in富山 - Flex Unit4Beta1+α -Fxug@北陸in富山 - Flex Unit4Beta1+α -
Fxug@北陸in富山 - Flex Unit4Beta1+α -
 
JDO 2019: Serverless Hype Driven Development - Grzegorz Piotrowski
JDO 2019: Serverless Hype Driven Development - Grzegorz Piotrowski JDO 2019: Serverless Hype Driven Development - Grzegorz Piotrowski
JDO 2019: Serverless Hype Driven Development - Grzegorz Piotrowski
 
Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrency
 
Async java8
Async java8Async java8
Async java8
 

Destaque

Automated Python Test Frameworks for Hardware Verification and Validation
Automated Python Test Frameworks for Hardware Verification and ValidationAutomated Python Test Frameworks for Hardware Verification and Validation
Automated Python Test Frameworks for Hardware Verification and Validation
Barbara Jones
 

Destaque (11)

Test Driven Development With Python
Test Driven Development With PythonTest Driven Development With Python
Test Driven Development With Python
 
Softwarequalitätssicherung mit Continuous Integration Tools
Softwarequalitätssicherung mit Continuous Integration ToolsSoftwarequalitätssicherung mit Continuous Integration Tools
Softwarequalitätssicherung mit Continuous Integration Tools
 
Python in Test automation
Python in Test automationPython in Test automation
Python in Test automation
 
Presentation TDD in Python
Presentation TDD in PythonPresentation TDD in Python
Presentation TDD in Python
 
Java EE 5
Java EE 5Java EE 5
Java EE 5
 
Clean Code Developer
Clean Code DeveloperClean Code Developer
Clean Code Developer
 
Easy selenium test automation on python
Easy selenium test automation on pythonEasy selenium test automation on python
Easy selenium test automation on python
 
Python Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit TestingPython Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit Testing
 
Automated Python Test Frameworks for Hardware Verification and Validation
Automated Python Test Frameworks for Hardware Verification and ValidationAutomated Python Test Frameworks for Hardware Verification and Validation
Automated Python Test Frameworks for Hardware Verification and Validation
 
Automated hardware testing using python
Automated hardware testing using pythonAutomated hardware testing using python
Automated hardware testing using python
 
無瑕的程式碼 Clean Code 心得分享
無瑕的程式碼 Clean Code 心得分享無瑕的程式碼 Clean Code 心得分享
無瑕的程式碼 Clean Code 心得分享
 

Semelhante a Mock testing mit Python

Semelhante a Mock testing mit Python (10)

Managing Mocks
Managing MocksManaging Mocks
Managing Mocks
 
Python testing using mock and pytest
Python testing using mock and pytestPython testing using mock and pytest
Python testing using mock and pytest
 
Fullstack Conference - Proxies before proxies: The hidden gems of Javascript...
Fullstack Conference -  Proxies before proxies: The hidden gems of Javascript...Fullstack Conference -  Proxies before proxies: The hidden gems of Javascript...
Fullstack Conference - Proxies before proxies: The hidden gems of Javascript...
 
PythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummiesPythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummies
 
Доклад Антона Поварова "Go in Badoo" с Golang Meetup
Доклад Антона Поварова "Go in Badoo" с Golang MeetupДоклад Антона Поварова "Go in Badoo" с Golang Meetup
Доклад Антона Поварова "Go in Badoo" с Golang Meetup
 
Jaap Groeneveld - Go Unit Testing Workshop
Jaap Groeneveld - Go Unit Testing WorkshopJaap Groeneveld - Go Unit Testing Workshop
Jaap Groeneveld - Go Unit Testing Workshop
 
Ansible for beginners ...?
Ansible for beginners ...?Ansible for beginners ...?
Ansible for beginners ...?
 
Python para equipos de ciberseguridad
Python para equipos de ciberseguridad Python para equipos de ciberseguridad
Python para equipos de ciberseguridad
 
Effective testing with pytest
Effective testing with pytestEffective testing with pytest
Effective testing with pytest
 
Unit testing without Robolectric, Droidcon Berlin 2016
Unit testing without Robolectric, Droidcon Berlin 2016Unit testing without Robolectric, Droidcon Berlin 2016
Unit testing without Robolectric, Droidcon Berlin 2016
 

Mais de Timo Stollenwerk

Einführung Test-driven Development
Einführung Test-driven DevelopmentEinführung Test-driven Development
Einführung Test-driven Development
Timo Stollenwerk
 

Mais de Timo Stollenwerk (20)

German Aerospace Center (DLR) Web Relaunch
German Aerospace Center (DLR) Web RelaunchGerman Aerospace Center (DLR) Web Relaunch
German Aerospace Center (DLR) Web Relaunch
 
Performance Testing (Python Barcamp Cologne 2020)
Performance Testing (Python Barcamp Cologne 2020)Performance Testing (Python Barcamp Cologne 2020)
Performance Testing (Python Barcamp Cologne 2020)
 
Python & JavaScript
Python & JavaScriptPython & JavaScript
Python & JavaScript
 
Roadmap to a Headless Plone
Roadmap to a Headless PloneRoadmap to a Headless Plone
Roadmap to a Headless Plone
 
Plone.restapi - a bridge to the modern web
Plone.restapi - a bridge to the modern webPlone.restapi - a bridge to the modern web
Plone.restapi - a bridge to the modern web
 
Divide et impera
Divide et imperaDivide et impera
Divide et impera
 
The Butler and The Snake (Europython 2015)
The Butler and The Snake (Europython 2015)The Butler and The Snake (Europython 2015)
The Butler and The Snake (Europython 2015)
 
Hypermedia APIs mit Javascript und Python
Hypermedia APIs mit Javascript und PythonHypermedia APIs mit Javascript und Python
Hypermedia APIs mit Javascript und Python
 
Plone Testing & Continuous Integration Team Report 2014
Plone Testing & Continuous Integration Team Report 2014Plone Testing & Continuous Integration Team Report 2014
Plone Testing & Continuous Integration Team Report 2014
 
The Beauty and the Beast - Modern Javascript Development with AngularJS and P...
The Beauty and the Beast - Modern Javascript Development with AngularJS and P...The Beauty and the Beast - Modern Javascript Development with AngularJS and P...
The Beauty and the Beast - Modern Javascript Development with AngularJS and P...
 
The Butler and the Snake - JCICPH
The Butler and the Snake - JCICPHThe Butler and the Snake - JCICPH
The Butler and the Snake - JCICPH
 
The Butler and the Snake - Continuous Integration for Python
The Butler and the Snake - Continuous Integration for PythonThe Butler and the Snake - Continuous Integration for Python
The Butler and the Snake - Continuous Integration for Python
 
AngularJS & Plone
AngularJS & PloneAngularJS & Plone
AngularJS & Plone
 
Who let the robot out? Qualitativ hochwertige Software durch Continuous Integ...
Who let the robot out? Qualitativ hochwertige Software durch Continuous Integ...Who let the robot out? Qualitativ hochwertige Software durch Continuous Integ...
Who let the robot out? Qualitativ hochwertige Software durch Continuous Integ...
 
Plone5
Plone5Plone5
Plone5
 
Who let the robot out? - Building high quality software with Continuous Integ...
Who let the robot out? - Building high quality software with Continuous Integ...Who let the robot out? - Building high quality software with Continuous Integ...
Who let the robot out? - Building high quality software with Continuous Integ...
 
The Future Is Written - Building next generation Plone sites with plone.app.c...
The Future Is Written - Building next generation Plone sites with plone.app.c...The Future Is Written - Building next generation Plone sites with plone.app.c...
The Future Is Written - Building next generation Plone sites with plone.app.c...
 
Plone Einführung
Plone EinführungPlone Einführung
Plone Einführung
 
Einführung Test-driven Development
Einführung Test-driven DevelopmentEinführung Test-driven Development
Einführung Test-driven Development
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
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, ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
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
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
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
 
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
 
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...
 

Mock testing mit Python

  • 1. Mock Testing mit Python PyBonn Meetup – März 2013 Timo Stollenwerk
  • 3. Ein Test ist kein Unit Test wenn ● Datenbankverbindung ● Netzwerkverbindung ● Dateisystemzugriff ● Externer Service
  • 4. Mocks in Python ● Mock ● Mocker ● pMock ● pyMock ● mox ● ...
  • 5. PostMonkey >>> from postmonkey import PostMonkey >>> pm = PostMonkey('your_api_key') >>> pm.ping() u"Everything's Chimpy!"
  • 6. Mocker >>> mocker = Mocker() >>> postmonkey = mocker.replace("postmonkey") >>> pm = postmonkey.PostMonkey(ANY) >>> pm.ping() >>> mocker.result(u"Everything's Chimpy!") >>> mocker.replay()
  • 7. Mocker: PostMonkey >>> from postmonkey import PostMonkey >>> pm = PostMonkey('your_api_key') >>> pm.ping() u"Everything's Chimpy!" >>> pm <mocker.Mock object at 0x9d7624c>
  • 8. Mock >>> @patch('postmonkey.PostMonkey') >>> def test_mailchimp_ping_method(mock_class): >>> mock_class().ping = MagicMock( >>> return_value=u"Everything's Chimpy!") >>> from postmonkey import PostMonkey >>> pm = PostMonkey('123') >>> assert pm.ping() == u"Everything's Chimpy!" >>> test_mailchimp_ping_method()
  • 9. Mock Testing mit Python PyBonn Meetup – März 2013 Timo Stollenwerk github.com/tisto/mock-testing-in-python