Mock testing mit Python
Upcoming SlideShare
Loading in...5
×
 

Mock testing mit Python

on

  • 605 views

 

Statistics

Views

Total Views
605
Views on SlideShare
605
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Mock testing mit Python Mock testing mit Python Presentation Transcript

  • Mock Testing mit PythonPyBonn Meetup – März 2013Timo 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"Everythings Chimpy!"
  • Mocker>>> mocker = Mocker()>>> postmonkey = mocker.replace("postmonkey")>>> pm = postmonkey.PostMonkey(ANY)>>> pm.ping()>>> mocker.result(u"Everythings Chimpy!")>>> mocker.replay()
  • Mocker: PostMonkey>>> from postmonkey import PostMonkey>>> pm = PostMonkey(your_api_key)>>> pm.ping()u"Everythings 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"Everythings Chimpy!")>>> from postmonkey import PostMonkey>>> pm = PostMonkey(123)>>> assert pm.ping() == u"Everythings Chimpy!">>> test_mailchimp_ping_method()
  • Mock Testing mit PythonPyBonn Meetup – März 2013Timo Stollenwerkgithub.com/tisto/mock-testing-in-python