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: PostMonkey>>> from postmonkey import PostMonkey>>> pm = PostMonkey(your_api_key)>>> pm.ping()u"Everythings Chimpy!...
Mock>>> @patch(postmonkey.PostMonkey)>>> def test_mailchimp_ping_method(mock_class):>>>    mock_class().ping = MagicMock(>...
Mock Testing mit PythonPyBonn Meetup – März 2013Timo Stollenwerkgithub.com/tisto/mock-testing-in-python
Upcoming SlideShare
Loading in...5
×

Mock testing mit Python

342

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
342
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Mock testing mit Python

  1. 1. Mock Testing mit PythonPyBonn Meetup – März 2013Timo Stollenwerk
  2. 2. Testing Pyramide
  3. 3. Ein Test ist kein Unit Test wenn● Datenbankverbindung● Netzwerkverbindung● Dateisystemzugriff● Externer Service
  4. 4. Mocks in Python● Mock● Mocker● pMock● pyMock● mox● ...
  5. 5. PostMonkey>>> from postmonkey import PostMonkey>>> pm = PostMonkey(your_api_key)>>> pm.ping()u"Everythings Chimpy!"
  6. 6. Mocker>>> mocker = Mocker()>>> postmonkey = mocker.replace("postmonkey")>>> pm = postmonkey.PostMonkey(ANY)>>> pm.ping()>>> mocker.result(u"Everythings Chimpy!")>>> mocker.replay()
  7. 7. Mocker: PostMonkey>>> from postmonkey import PostMonkey>>> pm = PostMonkey(your_api_key)>>> pm.ping()u"Everythings Chimpy!">>> pm<mocker.Mock object at 0x9d7624c>
  8. 8. 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()
  9. 9. Mock Testing mit PythonPyBonn Meetup – März 2013Timo Stollenwerkgithub.com/tisto/mock-testing-in-python
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×