SlideShare a Scribd company logo
Mock it right! A beginner’s guide to world
of tests and mocks.
Maciej Polańczyk
maciej.polanczyk@stxnext.pl
Mock, Patch
Schedule
- Class to be tested
- Basic test
- Mock
- Not the best mock
- The best mock - spec_set
- Good mock - spec
- Mock requests.post
- Patch
- Patch.object
- Patch & import
- Patch - raise Exception
- Patch - different return_value
- Patch - method instead of return_value
- Patch - nesting patches
- Patch - TestCase
- Patch - in setUp
- Patch - environment variables
https://docs.python.org/3/library/unittest.mock.html
Class to be tested
import requests
class MessageSender:
_max_attempts = 3
def send(self, message):
data = {
'from': message.sender,
'to': message.receiver,
'subject': message.subject,
}
for attempt in range(self._max_attempts):
response = requests.post(url='http://example.com/email', data=data)
if response.status_code == requests.codes.created:
return True
return False
Basic test
from message_sender import MessageSender
class MessageSenderTests(unittest.TestCase):
def test_should_send_message():
# GIVEN
message_sender = MessageSender()
message_to_be_sent = self._get_mocked_message()
# WHEN
result = message_sender.send(message_to_be_sent)
# THEN
self.assertTrue(result)
# assert correct arguments were passed to request.post
Mock
Use mock when you can pass it
Mock - creation
from unittest.mock import Mock
# mock and attributes
mock = Mock()
print(mock.not_existing_field)
<Mock name='mock.not_existing_field' id='4327526528'>
from unittest.mock import Mock
# mock and methods
mock = Mock()
print(mock.not_existing_method())
<Mock name='mock.not_existing_method()' id='4372615856'>
Mock - creation
from unittest.mock import Mock
# mock and attributes
mock = Mock()
mock.existing_field = 5
print(mock.existing_field)
5
from unittest.mock import Mock
# mock and methods
mock = Mock()
mock.existing_method.return_value = 5
print(mock.existing_method())
5
Mock - creation
from unittest.mock import Mock
# mock and attributes
mock = Mock(existing_field=5)
print(mock.existing_field)
5
from unittest.mock import Mock
# mock and methods
mock = Mock(existing_method=Mock(return_value=5))
print(mock.existing_method())
5
Mock - assertions
from unittest.mock import Mock
# in test method:
mock = Mock()
mock.existing_method.return_value = 5
# in source code:
mock.existing_method()
# in test method:
mock.existing_method.assert_called_once_with()
Mock - assertions
from unittest.mock import Mock
# in test method:
mock = Mock()
mock.existing_method.return_value = 5
# in source code:
mock.existing_method(1)
# in test method:
mock.existing_method.assert_called_once_with(1)
Mock - assertions
from unittest.mock import Mock
# in test method:
mock = Mock()
mock.existing_method.return_value = 5
# in source code:
mock.existing_method(1)
mock.existing_method(2)
# in test method:
mock.existing_method.assert_any_call(1)
Mock - assertions
from unittest.mock import Mock
# in test method:
mock = Mock()
mock.existing_method.return_value = 5
# in source code:
mock(3)
mock.existing_method(1)
mock.existing_method(2)
print(mock.call_args_list)
output from print: [call(3)]
Mock - assertions
from unittest.mock import Mock
# in test method:
mock = Mock()
mock.existing_method.return_value = 5
# in source code:
mock(3)
mock.existing_method(1)
mock.existing_method(2)
print(mock.method_calls)
output from print: [call.existing_method(1), call.existing_method(2)]
Mock - assertions
from unittest.mock import Mock
# in test method:
mock = Mock()
mock.existing_method.return_value = 5
# in source code:
mock(3)
mock.existing_method(1)
mock.existing_method(2)
print(mock.mock_calls)
output from print: [call(3), call.existing_method(1), call.existing_method(2)]
Mock - assertions
from unittest.mock import Mock, call
# in test method:
mock = Mock()
mock.existing_method.return_value = 5
# in source code:
mock(3)
mock.existing_method(1)
mock.existing_method(2)
# in test method:
self.assertEqual(mock.mock_calls, [call(3), call.existing_method(1), call.existing_method(2)])
self.assertEqual(mock.existing_method.mock_calls, [call(1), call(2)])
Not the best mock
from unittest.mock import Mock
@staticmethod
def _get_mocked_message():
message_mock = Mock(
receiver='maciej.polanczyk@stxnext.pl',
sender='maciej.polanczyk@test.com',
subject='testing sending message'
)
return message_mock
The best mock - spec_set
from unittest.mock import Mock
from message import Message
@staticmethod
def _get_mocked_message():
message_mock = Mock(
spec_set=Message,
receiver='maciej.polanczyk@stxnext.pl',
sender='maciej.polanczyk@test.com',
subject='testing sending message'
)
return message_mock
Message class
class Message:
receiver = None
sender = None
subject = None
Message class
def Message:
def __init__(self, receiver, sender, subject):
self.receiver = receiver
self.sender = sender
self.subject = subject
Good mock - spec
import requests
from unittest.mock import Mock
@staticmethod
def _get_success_response():
response_mock = Mock(
spec=requests.Response,
status_code=requests.codes.created
)
return response_mock
Good mock - spec
import requests
from unittest.mock import Mock
@staticmethod
def _get_failure_response():
response_mock = Mock(
spec=requests.Response,
status_code=requests.codes.bad
)
return response_mock
Basic test
from message_sender import MessageSender
class MessageSenderTests(unittest.TestCase):
def test_should_send_message():
# GIVEN
message_sender = MessageSender()
message_to_be_sent = self._get_mocked_message()
# WHEN
result = message_sender.send(message_to_be_sent)
# THEN
self.assertTrue(result)
# assert correct arguments were passed to request.post
Mock request.post
import requests
class MessageSender:
_max_attempts = 3
def send(self, message):
data = {
'from': message.sender,
'to': message.receiver,
'subject': message.subject,
}
for attempt in range(self._max_attempts):
response = requests.post(url='http://example.com/email', data=data)
if response.status_code == requests.codes.created:
return True
return False
Mock request.post
class MessageSender:
_max_attempts = 3
def __init__():
self._sender = ...
def send(self, message):
...
response = self._sender.post(
url='http://example.com/email',
data=data,
)
...
class MessageSenderTests(unittest.TestCase):
def test_should_send_message(self):
# GIVEN
message_sender = MessageSender()
message_sender._sender = self._get_mocked_post_method()
...
@staticmethod
def _get_mocked_post_method():
post_method_mock = Mock(
# spec_set=SenderClass
return_value=MessageSenderTests._get_success_response()
)
return post_method_mock
Patch
Use patch when you can not pass mock
Patch
from unittest.mock import patch
from message_sender import MessageSender
@patch('requests.post', autospec=True)
def test_should_send_message(self, post_mock):
# GIVEN
post_mock.return_value = self._get_success_response()
...
# THEN
self.assertTrue(result)
post_mock.assert_called_once_with(
data={
'from': 'maciej.polanczyk@test.com',
...
},
url='http://example.com/email'
)
Patch.object
import requests
from unittest.mock import patch
from message_sender import MessageSender
@patch.object(requests, 'post', autospec=True)
def test_should_send_message(self, post_mock):
# GIVEN
post_mock.return_value = self._get_success_response()
...
# THEN
self.assertTrue(result)
post_mock.assert_called_once_with(
data={
...
},
url='http://example.com/email'
)
Patch & imports
from requests import post
...
def send(self, message):
...
response = post(
url='http://example.com/email',
data=data,
)
...
from unittest.mock import patch
import message_sender
from message_sender import MessageSender
@patch.object(message_sender, 'post', autospec=True)
def test_should_send_message(self, post_mock):
...
import requests
...
def send(self, message):
...
response = requests.post(
url='http://example.com/email',
data=data,
)
…
import requests
from unittest.mock import patch
from message_sender import MessageSender
@patch.object(requests, 'post', autospec=True)
def test_should_send_message(self, post_mock):
...
Patch - raise Exception
import requests
class MessageSender:
_max_attempts = 3
def send(self, message):
data = {
'from': message.sender,
'to': message.receiver,
'subject': message.subject,
}
for attempt in range(self._max_attempts):
response = requests.post(url='http://example.com/email', data=data)
if response.status_code == requests.codes.created:
return True
return False
Patch - raise Exception
@patch.object(requests, 'post')
def test_should_not_catch_exception(self, post_mock):
# GIVEN
post_mock.side_effect = RequestException(
'Expected exception from unit tests'
)
message_sender = MessageSender()
message_to_be_sent = self._get_example_message()
# WHEN & THEN
with self.assertRaisesRegex(RequestException, 'Expected exception'):
message_sender.send(message_to_be_sent)
post_mock.assert_called_once_with(
data={
...
},
url='http://example.com/email'
)
Patch - different
return_value
import requests
class MessageSender:
_max_attempts = 3
def send(self, message):
data = {
'from': message.sender,
'to': message.receiver,
'subject': message.subject,
}
for attempt in range(self._max_attempts):
response = requests.post(url='http://example.com/email', data=data)
if response.status_code == requests.codes.created:
return True
return False
Patch - different
return_value
@patch.object(requests, 'post', autospec=True)
def test_should_retry_sending_when_incorrect_status_received(self, post_mock):
# GIVEN
post_mock.side_effect = [self._get_failure_response(),
self._get_failure_response(),
self._get_failure_response(),]
message_to_be_sent = self._get_example_message()
message_sender = MessageSender()
# WHEN
result = message_sender.send(message_to_be_sent)
# THEN
self.assertFalse(result)
expected_calls = [self._get_expected_call(),
self._get_expected_call(),
self._get_expected_call(),]
self.assertEqual(post_mock.call_args_list, expected_calls)
def _get_expected_call(self):
return call(
data = {
'from': 'maciej.polanczyk@test.com',
'subject': 'testing sending message',
'to': 'maciej.polanczyk@stxnext.pl'
},
url = 'http://example.com/email'
)
Patch - method instead
of return_value
@patch.object(requests, 'post', autospec=True)
def test_should_send_message_tooo(self, post_mock):
# GIVEN
def implementation_from_unit_test(*args, **kwargs):
return self._get_success_response()
post_mock.side_effect = implementation_from_unit_test
...
Patch - nesting patches
@patch.object(requests, 'post', autospec=True)
@patch.object(requests, 'get', autospec=True)
@patch.object(requests, 'put', autospec=True)
def test_should_send_message_tooo(self, put_mock, get_mock, post_mock):
# GIVEN
...
# WHEN
...
# THEN
...
Patch - TestCase
class MessageSenderTests(unittest.TestCase):
@patch.object(requests, 'post', autospec=True)
def test_should_send_message(self, post_mock):
pass
@patch.object(requests, 'post', autospec=True)
def test_should_not_catch_exception(self, post_mock):
pass
@patch.object(requests, 'post', autospec=True)
class MessageSenderTests(unittest.TestCase):
def test_should_send_message(self, post_mock):
pass
def test_should_not_catch_exception(self, post_mock):
pass
Patch - in setUp
class MessageSenderTests(unittest.TestCase):
def setUp(self):
super().setUp()
patcher = patch('requests.post')
self.addCleanup(patcher.stop)
self._post_mock = patcher.start()
def test_should_send_message(self):
# GIVEN
self._post_mock.return_value = self._get_success_response()
# WHEN
...
# THEN
...
Patch - environment
variables
class MessageSenderTests(unittest.TestCase):
@patch.dict('os.environ', {'not_existing_key': 'some_value'}, clear=True)
def test_should_override_environment_variables(self):
self.assertEqual(os.environ, {'not_existing_key': 'some_value'})
Summary
Use mock when you can pass it
Use patch when you can not pass mock
Thank you!
Questions?

More Related Content

What's hot

Unit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnitUnit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnit
Michelangelo van Dam
 
Unit Testing Presentation
Unit Testing PresentationUnit Testing Presentation
Unit Testing Presentation
nicobn
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnit
Michelangelo van Dam
 
Mocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnitMocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnit
mfrost503
 
Unit Testing using PHPUnit
Unit Testing using  PHPUnitUnit Testing using  PHPUnit
Unit Testing using PHPUnit
varuntaliyan
 
Parametrized testing, v2
Parametrized testing, v2Parametrized testing, v2
Parametrized testing, v2
Brian Okken
 
Test Driven Development with PHPUnit
Test Driven Development with PHPUnitTest Driven Development with PHPUnit
Test Driven Development with PHPUnit
Mindfire Solutions
 
PHPUnit: from zero to hero
PHPUnit: from zero to heroPHPUnit: from zero to hero
PHPUnit: from zero to hero
Jeremy Cook
 
Pytest: escreva menos, teste mais
Pytest: escreva menos, teste maisPytest: escreva menos, teste mais
Pytest: escreva menos, teste mais
Erick Wilder
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentation
Thanh Robi
 
Java programs
Java programsJava programs
Java programs
Mukund Gandrakota
 
PhpUnit Best Practices
PhpUnit Best PracticesPhpUnit Best Practices
PhpUnit Best Practices
Edorian
 
Unit testing with PHPUnit - there's life outside of TDD
Unit testing with PHPUnit - there's life outside of TDDUnit testing with PHPUnit - there's life outside of TDD
Unit testing with PHPUnit - there's life outside of TDD
Paweł Michalik
 
Test your code like a pro - PHPUnit in practice
Test your code like a pro - PHPUnit in practiceTest your code like a pro - PHPUnit in practice
Test your code like a pro - PHPUnit in practice
Sebastian Marek
 
Composing method
Composing methodComposing method
Composing method
С. Ариука
 
EPHPC Webinar Slides: Unit Testing by Arthur Purnama
EPHPC Webinar Slides: Unit Testing by Arthur PurnamaEPHPC Webinar Slides: Unit Testing by Arthur Purnama
EPHPC Webinar Slides: Unit Testing by Arthur Purnama
Enterprise PHP Center
 
New Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian BergmannNew Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian Bergmann
dpc
 
Advanced PHPUnit Testing
Advanced PHPUnit TestingAdvanced PHPUnit Testing
Advanced PHPUnit Testing
Mike Lively
 
Simulado java se 7 programmer
Simulado java se 7 programmerSimulado java se 7 programmer
Simulado java se 7 programmer
Miguel Vilaca
 
Python Unit Test
Python Unit TestPython Unit Test
Python Unit Test
David Xie
 

What's hot (20)

Unit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnitUnit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnit
 
Unit Testing Presentation
Unit Testing PresentationUnit Testing Presentation
Unit Testing Presentation
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnit
 
Mocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnitMocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnit
 
Unit Testing using PHPUnit
Unit Testing using  PHPUnitUnit Testing using  PHPUnit
Unit Testing using PHPUnit
 
Parametrized testing, v2
Parametrized testing, v2Parametrized testing, v2
Parametrized testing, v2
 
Test Driven Development with PHPUnit
Test Driven Development with PHPUnitTest Driven Development with PHPUnit
Test Driven Development with PHPUnit
 
PHPUnit: from zero to hero
PHPUnit: from zero to heroPHPUnit: from zero to hero
PHPUnit: from zero to hero
 
Pytest: escreva menos, teste mais
Pytest: escreva menos, teste maisPytest: escreva menos, teste mais
Pytest: escreva menos, teste mais
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentation
 
Java programs
Java programsJava programs
Java programs
 
PhpUnit Best Practices
PhpUnit Best PracticesPhpUnit Best Practices
PhpUnit Best Practices
 
Unit testing with PHPUnit - there's life outside of TDD
Unit testing with PHPUnit - there's life outside of TDDUnit testing with PHPUnit - there's life outside of TDD
Unit testing with PHPUnit - there's life outside of TDD
 
Test your code like a pro - PHPUnit in practice
Test your code like a pro - PHPUnit in practiceTest your code like a pro - PHPUnit in practice
Test your code like a pro - PHPUnit in practice
 
Composing method
Composing methodComposing method
Composing method
 
EPHPC Webinar Slides: Unit Testing by Arthur Purnama
EPHPC Webinar Slides: Unit Testing by Arthur PurnamaEPHPC Webinar Slides: Unit Testing by Arthur Purnama
EPHPC Webinar Slides: Unit Testing by Arthur Purnama
 
New Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian BergmannNew Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian Bergmann
 
Advanced PHPUnit Testing
Advanced PHPUnit TestingAdvanced PHPUnit Testing
Advanced PHPUnit Testing
 
Simulado java se 7 programmer
Simulado java se 7 programmerSimulado java se 7 programmer
Simulado java se 7 programmer
 
Python Unit Test
Python Unit TestPython Unit Test
Python Unit Test
 

Viewers also liked

How to apply deep learning to 3 d objects
How to apply deep learning to 3 d objectsHow to apply deep learning to 3 d objects
How to apply deep learning to 3 d objects
Ogushi Masaya
 
EuroPython 2017 - How to make money with your Python open-source project
EuroPython 2017 - How to make money with your Python open-source projectEuroPython 2017 - How to make money with your Python open-source project
EuroPython 2017 - How to make money with your Python open-source project
Max Tepkeev
 
Europy17_dibernardo
Europy17_dibernardoEuropy17_dibernardo
Europy17_dibernardo
GIUSEPPE DI BERNARDO
 
Type Annotations in Python: Whats, Whys and Wows!
Type Annotations in Python: Whats, Whys and Wows!Type Annotations in Python: Whats, Whys and Wows!
Type Annotations in Python: Whats, Whys and Wows!
Andreas Dewes
 
OpenAPI development with Python
OpenAPI development with PythonOpenAPI development with Python
OpenAPI development with Python
Takuro Wada
 
EuroPython 2017 - PyData - Deep Learning your Broadband Network @ HOME
EuroPython 2017 - PyData - Deep Learning your Broadband Network @ HOMEEuroPython 2017 - PyData - Deep Learning your Broadband Network @ HOME
EuroPython 2017 - PyData - Deep Learning your Broadband Network @ HOME
HONGJOO LEE
 

Viewers also liked (6)

How to apply deep learning to 3 d objects
How to apply deep learning to 3 d objectsHow to apply deep learning to 3 d objects
How to apply deep learning to 3 d objects
 
EuroPython 2017 - How to make money with your Python open-source project
EuroPython 2017 - How to make money with your Python open-source projectEuroPython 2017 - How to make money with your Python open-source project
EuroPython 2017 - How to make money with your Python open-source project
 
Europy17_dibernardo
Europy17_dibernardoEuropy17_dibernardo
Europy17_dibernardo
 
Type Annotations in Python: Whats, Whys and Wows!
Type Annotations in Python: Whats, Whys and Wows!Type Annotations in Python: Whats, Whys and Wows!
Type Annotations in Python: Whats, Whys and Wows!
 
OpenAPI development with Python
OpenAPI development with PythonOpenAPI development with Python
OpenAPI development with Python
 
EuroPython 2017 - PyData - Deep Learning your Broadband Network @ HOME
EuroPython 2017 - PyData - Deep Learning your Broadband Network @ HOMEEuroPython 2017 - PyData - Deep Learning your Broadband Network @ HOME
EuroPython 2017 - PyData - Deep Learning your Broadband Network @ HOME
 

Similar to Mock it right! A beginner’s guide to world of tests and mocks, Maciej Polańczyk

Auto testing!
Auto testing!Auto testing!
Auto testing!
Kwangsoo Shin
 
Pruebas unitarias con django
Pruebas unitarias con djangoPruebas unitarias con django
Pruebas unitarias con django
Tomás Henríquez
 
Objective-c Runtime
Objective-c RuntimeObjective-c Runtime
Objective-c Runtime
Pavel Albitsky
 
Managing Mocks
Managing MocksManaging Mocks
Managing Mocks
Helen Sherwood-Taylor
 
Advanced Django
Advanced DjangoAdvanced Django
Advanced Django
Simon Willison
 
How to fake_properly
How to fake_properlyHow to fake_properly
How to fake_properly
Rainer Schuettengruber
 
Spock the enterprise ready specifiation framework - Ted Vinke
Spock the enterprise ready specifiation framework - Ted VinkeSpock the enterprise ready specifiation framework - Ted Vinke
Spock the enterprise ready specifiation framework - Ted Vinke
Ted Vinke
 
Python programming : Inheritance and polymorphism
Python programming : Inheritance and polymorphismPython programming : Inheritance and polymorphism
Python programming : Inheritance and polymorphism
Emertxe Information Technologies Pvt Ltd
 
Test driven development_for_php
Test driven development_for_phpTest driven development_for_php
Test driven development_for_php
Lean Teams Consultancy
 
Mutation Testing: Testing your tests
Mutation Testing: Testing your testsMutation Testing: Testing your tests
Mutation Testing: Testing your tests
Stephen Leigh
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdf
Hans Jones
 
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
Maulik Borsaniya
 
Django (Web Konferencia 2009)
Django (Web Konferencia 2009)Django (Web Konferencia 2009)
Django (Web Konferencia 2009)
Szilveszter Farkas
 
How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everything
noelrap
 
Unit testing
Unit testingUnit testing
Testers guide to unit testing
Testers guide to unit testingTesters guide to unit testing
Testers guide to unit testing
Craig Risi
 
wk5ppt2_Iris
wk5ppt2_Iriswk5ppt2_Iris
wk5ppt2_Iris
AliciaWei1
 
pytest로 파이썬 코드 테스트하기
pytest로 파이썬 코드 테스트하기pytest로 파이썬 코드 테스트하기
pytest로 파이썬 코드 테스트하기
Yeongseon Choe
 
Mocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnitMocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnit
mfrost503
 
Unit testing zend framework apps
Unit testing zend framework appsUnit testing zend framework apps
Unit testing zend framework apps
Michelangelo van Dam
 

Similar to Mock it right! A beginner’s guide to world of tests and mocks, Maciej Polańczyk (20)

Auto testing!
Auto testing!Auto testing!
Auto testing!
 
Pruebas unitarias con django
Pruebas unitarias con djangoPruebas unitarias con django
Pruebas unitarias con django
 
Objective-c Runtime
Objective-c RuntimeObjective-c Runtime
Objective-c Runtime
 
Managing Mocks
Managing MocksManaging Mocks
Managing Mocks
 
Advanced Django
Advanced DjangoAdvanced Django
Advanced Django
 
How to fake_properly
How to fake_properlyHow to fake_properly
How to fake_properly
 
Spock the enterprise ready specifiation framework - Ted Vinke
Spock the enterprise ready specifiation framework - Ted VinkeSpock the enterprise ready specifiation framework - Ted Vinke
Spock the enterprise ready specifiation framework - Ted Vinke
 
Python programming : Inheritance and polymorphism
Python programming : Inheritance and polymorphismPython programming : Inheritance and polymorphism
Python programming : Inheritance and polymorphism
 
Test driven development_for_php
Test driven development_for_phpTest driven development_for_php
Test driven development_for_php
 
Mutation Testing: Testing your tests
Mutation Testing: Testing your testsMutation Testing: Testing your tests
Mutation Testing: Testing your tests
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdf
 
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
 
Django (Web Konferencia 2009)
Django (Web Konferencia 2009)Django (Web Konferencia 2009)
Django (Web Konferencia 2009)
 
How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everything
 
Unit testing
Unit testingUnit testing
Unit testing
 
Testers guide to unit testing
Testers guide to unit testingTesters guide to unit testing
Testers guide to unit testing
 
wk5ppt2_Iris
wk5ppt2_Iriswk5ppt2_Iris
wk5ppt2_Iris
 
pytest로 파이썬 코드 테스트하기
pytest로 파이썬 코드 테스트하기pytest로 파이썬 코드 테스트하기
pytest로 파이썬 코드 테스트하기
 
Mocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnitMocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnit
 
Unit testing zend framework apps
Unit testing zend framework appsUnit testing zend framework apps
Unit testing zend framework apps
 

More from Pôle Systematic Paris-Region

OSIS19_IoT :Transparent remote connectivity to short-range IoT devices, by Na...
OSIS19_IoT :Transparent remote connectivity to short-range IoT devices, by Na...OSIS19_IoT :Transparent remote connectivity to short-range IoT devices, by Na...
OSIS19_IoT :Transparent remote connectivity to short-range IoT devices, by Na...
Pôle Systematic Paris-Region
 
OSIS19_Cloud : SAFC: Scheduling and Allocation Framework for Containers in a ...
OSIS19_Cloud : SAFC: Scheduling and Allocation Framework for Containers in a ...OSIS19_Cloud : SAFC: Scheduling and Allocation Framework for Containers in a ...
OSIS19_Cloud : SAFC: Scheduling and Allocation Framework for Containers in a ...
Pôle Systematic Paris-Region
 
OSIS19_Cloud : Qu’apporte l’observabilité à la gestion de configuration? par ...
OSIS19_Cloud : Qu’apporte l’observabilité à la gestion de configuration? par ...OSIS19_Cloud : Qu’apporte l’observabilité à la gestion de configuration? par ...
OSIS19_Cloud : Qu’apporte l’observabilité à la gestion de configuration? par ...
Pôle Systematic Paris-Region
 
OSIS19_Cloud : Performance and power management in virtualized data centers, ...
OSIS19_Cloud : Performance and power management in virtualized data centers, ...OSIS19_Cloud : Performance and power management in virtualized data centers, ...
OSIS19_Cloud : Performance and power management in virtualized data centers, ...
Pôle Systematic Paris-Region
 
OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ...
OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ...OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ...
OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ...
Pôle Systematic Paris-Region
 
OSIS19_Cloud : Attribution automatique de ressources pour micro-services, Alt...
OSIS19_Cloud : Attribution automatique de ressources pour micro-services, Alt...OSIS19_Cloud : Attribution automatique de ressources pour micro-services, Alt...
OSIS19_Cloud : Attribution automatique de ressources pour micro-services, Alt...
Pôle Systematic Paris-Region
 
OSIS19_IoT : State of the art in security for embedded systems and IoT, by Pi...
OSIS19_IoT : State of the art in security for embedded systems and IoT, by Pi...OSIS19_IoT : State of the art in security for embedded systems and IoT, by Pi...
OSIS19_IoT : State of the art in security for embedded systems and IoT, by Pi...
Pôle Systematic Paris-Region
 
Osis19_IoT: Proof of Pointer Programs with Ownership in SPARK, by Yannick Moy
Osis19_IoT: Proof of Pointer Programs with Ownership in SPARK, by Yannick MoyOsis19_IoT: Proof of Pointer Programs with Ownership in SPARK, by Yannick Moy
Osis19_IoT: Proof of Pointer Programs with Ownership in SPARK, by Yannick Moy
Pôle Systematic Paris-Region
 
Osis18_Cloud : Pas de commun sans communauté ?
Osis18_Cloud : Pas de commun sans communauté ?Osis18_Cloud : Pas de commun sans communauté ?
Osis18_Cloud : Pas de commun sans communauté ?
Pôle Systematic Paris-Region
 
Osis18_Cloud : Projet Wolphin
Osis18_Cloud : Projet Wolphin Osis18_Cloud : Projet Wolphin
Osis18_Cloud : Projet Wolphin
Pôle Systematic Paris-Region
 
Osis18_Cloud : Virtualisation efficace d’architectures NUMA
Osis18_Cloud : Virtualisation efficace d’architectures NUMAOsis18_Cloud : Virtualisation efficace d’architectures NUMA
Osis18_Cloud : Virtualisation efficace d’architectures NUMA
Pôle Systematic Paris-Region
 
Osis18_Cloud : DeepTorrent Stockage distribué perenne basé sur Bittorrent
Osis18_Cloud : DeepTorrent Stockage distribué perenne basé sur BittorrentOsis18_Cloud : DeepTorrent Stockage distribué perenne basé sur Bittorrent
Osis18_Cloud : DeepTorrent Stockage distribué perenne basé sur Bittorrent
Pôle Systematic Paris-Region
 
Osis18_Cloud : Software-heritage
Osis18_Cloud : Software-heritageOsis18_Cloud : Software-heritage
Osis18_Cloud : Software-heritage
Pôle Systematic Paris-Region
 
OSIS18_IoT: L'approche machine virtuelle pour les microcontrôleurs, le projet...
OSIS18_IoT: L'approche machine virtuelle pour les microcontrôleurs, le projet...OSIS18_IoT: L'approche machine virtuelle pour les microcontrôleurs, le projet...
OSIS18_IoT: L'approche machine virtuelle pour les microcontrôleurs, le projet...
Pôle Systematic Paris-Region
 
OSIS18_IoT: La securite des objets connectes a bas cout avec l'os et riot
OSIS18_IoT: La securite des objets connectes a bas cout avec l'os et riotOSIS18_IoT: La securite des objets connectes a bas cout avec l'os et riot
OSIS18_IoT: La securite des objets connectes a bas cout avec l'os et riot
Pôle Systematic Paris-Region
 
OSIS18_IoT : Solution de mise au point pour les systemes embarques, par Julio...
OSIS18_IoT : Solution de mise au point pour les systemes embarques, par Julio...OSIS18_IoT : Solution de mise au point pour les systemes embarques, par Julio...
OSIS18_IoT : Solution de mise au point pour les systemes embarques, par Julio...
Pôle Systematic Paris-Region
 
OSIS18_IoT : Securisation du reseau des objets connectes, par Nicolas LE SAUZ...
OSIS18_IoT : Securisation du reseau des objets connectes, par Nicolas LE SAUZ...OSIS18_IoT : Securisation du reseau des objets connectes, par Nicolas LE SAUZ...
OSIS18_IoT : Securisation du reseau des objets connectes, par Nicolas LE SAUZ...
Pôle Systematic Paris-Region
 
OSIS18_IoT : Ada and SPARK - Defense in Depth for Safe Micro-controller Progr...
OSIS18_IoT : Ada and SPARK - Defense in Depth for Safe Micro-controller Progr...OSIS18_IoT : Ada and SPARK - Defense in Depth for Safe Micro-controller Progr...
OSIS18_IoT : Ada and SPARK - Defense in Depth for Safe Micro-controller Progr...
Pôle Systematic Paris-Region
 
OSIS18_IoT : RTEMS pour l'IoT professionnel, par Pierre Ficheux (Smile ECS)
OSIS18_IoT : RTEMS pour l'IoT professionnel, par Pierre Ficheux (Smile ECS)OSIS18_IoT : RTEMS pour l'IoT professionnel, par Pierre Ficheux (Smile ECS)
OSIS18_IoT : RTEMS pour l'IoT professionnel, par Pierre Ficheux (Smile ECS)
Pôle Systematic Paris-Region
 
PyParis 2017 / Un mooc python, by thierry parmentelat
PyParis 2017 / Un mooc python, by thierry parmentelatPyParis 2017 / Un mooc python, by thierry parmentelat
PyParis 2017 / Un mooc python, by thierry parmentelat
Pôle Systematic Paris-Region
 

More from Pôle Systematic Paris-Region (20)

OSIS19_IoT :Transparent remote connectivity to short-range IoT devices, by Na...
OSIS19_IoT :Transparent remote connectivity to short-range IoT devices, by Na...OSIS19_IoT :Transparent remote connectivity to short-range IoT devices, by Na...
OSIS19_IoT :Transparent remote connectivity to short-range IoT devices, by Na...
 
OSIS19_Cloud : SAFC: Scheduling and Allocation Framework for Containers in a ...
OSIS19_Cloud : SAFC: Scheduling and Allocation Framework for Containers in a ...OSIS19_Cloud : SAFC: Scheduling and Allocation Framework for Containers in a ...
OSIS19_Cloud : SAFC: Scheduling and Allocation Framework for Containers in a ...
 
OSIS19_Cloud : Qu’apporte l’observabilité à la gestion de configuration? par ...
OSIS19_Cloud : Qu’apporte l’observabilité à la gestion de configuration? par ...OSIS19_Cloud : Qu’apporte l’observabilité à la gestion de configuration? par ...
OSIS19_Cloud : Qu’apporte l’observabilité à la gestion de configuration? par ...
 
OSIS19_Cloud : Performance and power management in virtualized data centers, ...
OSIS19_Cloud : Performance and power management in virtualized data centers, ...OSIS19_Cloud : Performance and power management in virtualized data centers, ...
OSIS19_Cloud : Performance and power management in virtualized data centers, ...
 
OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ...
OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ...OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ...
OSIS19_Cloud : Des objets dans le cloud, et qui y restent -- L'expérience du ...
 
OSIS19_Cloud : Attribution automatique de ressources pour micro-services, Alt...
OSIS19_Cloud : Attribution automatique de ressources pour micro-services, Alt...OSIS19_Cloud : Attribution automatique de ressources pour micro-services, Alt...
OSIS19_Cloud : Attribution automatique de ressources pour micro-services, Alt...
 
OSIS19_IoT : State of the art in security for embedded systems and IoT, by Pi...
OSIS19_IoT : State of the art in security for embedded systems and IoT, by Pi...OSIS19_IoT : State of the art in security for embedded systems and IoT, by Pi...
OSIS19_IoT : State of the art in security for embedded systems and IoT, by Pi...
 
Osis19_IoT: Proof of Pointer Programs with Ownership in SPARK, by Yannick Moy
Osis19_IoT: Proof of Pointer Programs with Ownership in SPARK, by Yannick MoyOsis19_IoT: Proof of Pointer Programs with Ownership in SPARK, by Yannick Moy
Osis19_IoT: Proof of Pointer Programs with Ownership in SPARK, by Yannick Moy
 
Osis18_Cloud : Pas de commun sans communauté ?
Osis18_Cloud : Pas de commun sans communauté ?Osis18_Cloud : Pas de commun sans communauté ?
Osis18_Cloud : Pas de commun sans communauté ?
 
Osis18_Cloud : Projet Wolphin
Osis18_Cloud : Projet Wolphin Osis18_Cloud : Projet Wolphin
Osis18_Cloud : Projet Wolphin
 
Osis18_Cloud : Virtualisation efficace d’architectures NUMA
Osis18_Cloud : Virtualisation efficace d’architectures NUMAOsis18_Cloud : Virtualisation efficace d’architectures NUMA
Osis18_Cloud : Virtualisation efficace d’architectures NUMA
 
Osis18_Cloud : DeepTorrent Stockage distribué perenne basé sur Bittorrent
Osis18_Cloud : DeepTorrent Stockage distribué perenne basé sur BittorrentOsis18_Cloud : DeepTorrent Stockage distribué perenne basé sur Bittorrent
Osis18_Cloud : DeepTorrent Stockage distribué perenne basé sur Bittorrent
 
Osis18_Cloud : Software-heritage
Osis18_Cloud : Software-heritageOsis18_Cloud : Software-heritage
Osis18_Cloud : Software-heritage
 
OSIS18_IoT: L'approche machine virtuelle pour les microcontrôleurs, le projet...
OSIS18_IoT: L'approche machine virtuelle pour les microcontrôleurs, le projet...OSIS18_IoT: L'approche machine virtuelle pour les microcontrôleurs, le projet...
OSIS18_IoT: L'approche machine virtuelle pour les microcontrôleurs, le projet...
 
OSIS18_IoT: La securite des objets connectes a bas cout avec l'os et riot
OSIS18_IoT: La securite des objets connectes a bas cout avec l'os et riotOSIS18_IoT: La securite des objets connectes a bas cout avec l'os et riot
OSIS18_IoT: La securite des objets connectes a bas cout avec l'os et riot
 
OSIS18_IoT : Solution de mise au point pour les systemes embarques, par Julio...
OSIS18_IoT : Solution de mise au point pour les systemes embarques, par Julio...OSIS18_IoT : Solution de mise au point pour les systemes embarques, par Julio...
OSIS18_IoT : Solution de mise au point pour les systemes embarques, par Julio...
 
OSIS18_IoT : Securisation du reseau des objets connectes, par Nicolas LE SAUZ...
OSIS18_IoT : Securisation du reseau des objets connectes, par Nicolas LE SAUZ...OSIS18_IoT : Securisation du reseau des objets connectes, par Nicolas LE SAUZ...
OSIS18_IoT : Securisation du reseau des objets connectes, par Nicolas LE SAUZ...
 
OSIS18_IoT : Ada and SPARK - Defense in Depth for Safe Micro-controller Progr...
OSIS18_IoT : Ada and SPARK - Defense in Depth for Safe Micro-controller Progr...OSIS18_IoT : Ada and SPARK - Defense in Depth for Safe Micro-controller Progr...
OSIS18_IoT : Ada and SPARK - Defense in Depth for Safe Micro-controller Progr...
 
OSIS18_IoT : RTEMS pour l'IoT professionnel, par Pierre Ficheux (Smile ECS)
OSIS18_IoT : RTEMS pour l'IoT professionnel, par Pierre Ficheux (Smile ECS)OSIS18_IoT : RTEMS pour l'IoT professionnel, par Pierre Ficheux (Smile ECS)
OSIS18_IoT : RTEMS pour l'IoT professionnel, par Pierre Ficheux (Smile ECS)
 
PyParis 2017 / Un mooc python, by thierry parmentelat
PyParis 2017 / Un mooc python, by thierry parmentelatPyParis 2017 / Un mooc python, by thierry parmentelat
PyParis 2017 / Un mooc python, by thierry parmentelat
 

Recently uploaded

Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
marufrahmanstratejm
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
Neo4j
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 

Recently uploaded (20)

Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 

Mock it right! A beginner’s guide to world of tests and mocks, Maciej Polańczyk

  • 1. Mock it right! A beginner’s guide to world of tests and mocks. Maciej Polańczyk maciej.polanczyk@stxnext.pl Mock, Patch
  • 2. Schedule - Class to be tested - Basic test - Mock - Not the best mock - The best mock - spec_set - Good mock - spec - Mock requests.post - Patch - Patch.object - Patch & import - Patch - raise Exception - Patch - different return_value - Patch - method instead of return_value - Patch - nesting patches - Patch - TestCase - Patch - in setUp - Patch - environment variables https://docs.python.org/3/library/unittest.mock.html
  • 3. Class to be tested import requests class MessageSender: _max_attempts = 3 def send(self, message): data = { 'from': message.sender, 'to': message.receiver, 'subject': message.subject, } for attempt in range(self._max_attempts): response = requests.post(url='http://example.com/email', data=data) if response.status_code == requests.codes.created: return True return False
  • 4. Basic test from message_sender import MessageSender class MessageSenderTests(unittest.TestCase): def test_should_send_message(): # GIVEN message_sender = MessageSender() message_to_be_sent = self._get_mocked_message() # WHEN result = message_sender.send(message_to_be_sent) # THEN self.assertTrue(result) # assert correct arguments were passed to request.post
  • 5. Mock Use mock when you can pass it
  • 6. Mock - creation from unittest.mock import Mock # mock and attributes mock = Mock() print(mock.not_existing_field) <Mock name='mock.not_existing_field' id='4327526528'> from unittest.mock import Mock # mock and methods mock = Mock() print(mock.not_existing_method()) <Mock name='mock.not_existing_method()' id='4372615856'>
  • 7. Mock - creation from unittest.mock import Mock # mock and attributes mock = Mock() mock.existing_field = 5 print(mock.existing_field) 5 from unittest.mock import Mock # mock and methods mock = Mock() mock.existing_method.return_value = 5 print(mock.existing_method()) 5
  • 8. Mock - creation from unittest.mock import Mock # mock and attributes mock = Mock(existing_field=5) print(mock.existing_field) 5 from unittest.mock import Mock # mock and methods mock = Mock(existing_method=Mock(return_value=5)) print(mock.existing_method()) 5
  • 9. Mock - assertions from unittest.mock import Mock # in test method: mock = Mock() mock.existing_method.return_value = 5 # in source code: mock.existing_method() # in test method: mock.existing_method.assert_called_once_with()
  • 10. Mock - assertions from unittest.mock import Mock # in test method: mock = Mock() mock.existing_method.return_value = 5 # in source code: mock.existing_method(1) # in test method: mock.existing_method.assert_called_once_with(1)
  • 11. Mock - assertions from unittest.mock import Mock # in test method: mock = Mock() mock.existing_method.return_value = 5 # in source code: mock.existing_method(1) mock.existing_method(2) # in test method: mock.existing_method.assert_any_call(1)
  • 12. Mock - assertions from unittest.mock import Mock # in test method: mock = Mock() mock.existing_method.return_value = 5 # in source code: mock(3) mock.existing_method(1) mock.existing_method(2) print(mock.call_args_list) output from print: [call(3)]
  • 13. Mock - assertions from unittest.mock import Mock # in test method: mock = Mock() mock.existing_method.return_value = 5 # in source code: mock(3) mock.existing_method(1) mock.existing_method(2) print(mock.method_calls) output from print: [call.existing_method(1), call.existing_method(2)]
  • 14. Mock - assertions from unittest.mock import Mock # in test method: mock = Mock() mock.existing_method.return_value = 5 # in source code: mock(3) mock.existing_method(1) mock.existing_method(2) print(mock.mock_calls) output from print: [call(3), call.existing_method(1), call.existing_method(2)]
  • 15. Mock - assertions from unittest.mock import Mock, call # in test method: mock = Mock() mock.existing_method.return_value = 5 # in source code: mock(3) mock.existing_method(1) mock.existing_method(2) # in test method: self.assertEqual(mock.mock_calls, [call(3), call.existing_method(1), call.existing_method(2)]) self.assertEqual(mock.existing_method.mock_calls, [call(1), call(2)])
  • 16. Not the best mock from unittest.mock import Mock @staticmethod def _get_mocked_message(): message_mock = Mock( receiver='maciej.polanczyk@stxnext.pl', sender='maciej.polanczyk@test.com', subject='testing sending message' ) return message_mock
  • 17. The best mock - spec_set from unittest.mock import Mock from message import Message @staticmethod def _get_mocked_message(): message_mock = Mock( spec_set=Message, receiver='maciej.polanczyk@stxnext.pl', sender='maciej.polanczyk@test.com', subject='testing sending message' ) return message_mock
  • 18. Message class class Message: receiver = None sender = None subject = None
  • 19. Message class def Message: def __init__(self, receiver, sender, subject): self.receiver = receiver self.sender = sender self.subject = subject
  • 20. Good mock - spec import requests from unittest.mock import Mock @staticmethod def _get_success_response(): response_mock = Mock( spec=requests.Response, status_code=requests.codes.created ) return response_mock
  • 21. Good mock - spec import requests from unittest.mock import Mock @staticmethod def _get_failure_response(): response_mock = Mock( spec=requests.Response, status_code=requests.codes.bad ) return response_mock
  • 22. Basic test from message_sender import MessageSender class MessageSenderTests(unittest.TestCase): def test_should_send_message(): # GIVEN message_sender = MessageSender() message_to_be_sent = self._get_mocked_message() # WHEN result = message_sender.send(message_to_be_sent) # THEN self.assertTrue(result) # assert correct arguments were passed to request.post
  • 23. Mock request.post import requests class MessageSender: _max_attempts = 3 def send(self, message): data = { 'from': message.sender, 'to': message.receiver, 'subject': message.subject, } for attempt in range(self._max_attempts): response = requests.post(url='http://example.com/email', data=data) if response.status_code == requests.codes.created: return True return False
  • 24. Mock request.post class MessageSender: _max_attempts = 3 def __init__(): self._sender = ... def send(self, message): ... response = self._sender.post( url='http://example.com/email', data=data, ) ... class MessageSenderTests(unittest.TestCase): def test_should_send_message(self): # GIVEN message_sender = MessageSender() message_sender._sender = self._get_mocked_post_method() ... @staticmethod def _get_mocked_post_method(): post_method_mock = Mock( # spec_set=SenderClass return_value=MessageSenderTests._get_success_response() ) return post_method_mock
  • 25. Patch Use patch when you can not pass mock
  • 26. Patch from unittest.mock import patch from message_sender import MessageSender @patch('requests.post', autospec=True) def test_should_send_message(self, post_mock): # GIVEN post_mock.return_value = self._get_success_response() ... # THEN self.assertTrue(result) post_mock.assert_called_once_with( data={ 'from': 'maciej.polanczyk@test.com', ... }, url='http://example.com/email' )
  • 27. Patch.object import requests from unittest.mock import patch from message_sender import MessageSender @patch.object(requests, 'post', autospec=True) def test_should_send_message(self, post_mock): # GIVEN post_mock.return_value = self._get_success_response() ... # THEN self.assertTrue(result) post_mock.assert_called_once_with( data={ ... }, url='http://example.com/email' )
  • 28. Patch & imports from requests import post ... def send(self, message): ... response = post( url='http://example.com/email', data=data, ) ... from unittest.mock import patch import message_sender from message_sender import MessageSender @patch.object(message_sender, 'post', autospec=True) def test_should_send_message(self, post_mock): ... import requests ... def send(self, message): ... response = requests.post( url='http://example.com/email', data=data, ) … import requests from unittest.mock import patch from message_sender import MessageSender @patch.object(requests, 'post', autospec=True) def test_should_send_message(self, post_mock): ...
  • 29. Patch - raise Exception import requests class MessageSender: _max_attempts = 3 def send(self, message): data = { 'from': message.sender, 'to': message.receiver, 'subject': message.subject, } for attempt in range(self._max_attempts): response = requests.post(url='http://example.com/email', data=data) if response.status_code == requests.codes.created: return True return False
  • 30. Patch - raise Exception @patch.object(requests, 'post') def test_should_not_catch_exception(self, post_mock): # GIVEN post_mock.side_effect = RequestException( 'Expected exception from unit tests' ) message_sender = MessageSender() message_to_be_sent = self._get_example_message() # WHEN & THEN with self.assertRaisesRegex(RequestException, 'Expected exception'): message_sender.send(message_to_be_sent) post_mock.assert_called_once_with( data={ ... }, url='http://example.com/email' )
  • 31. Patch - different return_value import requests class MessageSender: _max_attempts = 3 def send(self, message): data = { 'from': message.sender, 'to': message.receiver, 'subject': message.subject, } for attempt in range(self._max_attempts): response = requests.post(url='http://example.com/email', data=data) if response.status_code == requests.codes.created: return True return False
  • 32. Patch - different return_value @patch.object(requests, 'post', autospec=True) def test_should_retry_sending_when_incorrect_status_received(self, post_mock): # GIVEN post_mock.side_effect = [self._get_failure_response(), self._get_failure_response(), self._get_failure_response(),] message_to_be_sent = self._get_example_message() message_sender = MessageSender() # WHEN result = message_sender.send(message_to_be_sent) # THEN self.assertFalse(result) expected_calls = [self._get_expected_call(), self._get_expected_call(), self._get_expected_call(),] self.assertEqual(post_mock.call_args_list, expected_calls) def _get_expected_call(self): return call( data = { 'from': 'maciej.polanczyk@test.com', 'subject': 'testing sending message', 'to': 'maciej.polanczyk@stxnext.pl' }, url = 'http://example.com/email' )
  • 33. Patch - method instead of return_value @patch.object(requests, 'post', autospec=True) def test_should_send_message_tooo(self, post_mock): # GIVEN def implementation_from_unit_test(*args, **kwargs): return self._get_success_response() post_mock.side_effect = implementation_from_unit_test ...
  • 34. Patch - nesting patches @patch.object(requests, 'post', autospec=True) @patch.object(requests, 'get', autospec=True) @patch.object(requests, 'put', autospec=True) def test_should_send_message_tooo(self, put_mock, get_mock, post_mock): # GIVEN ... # WHEN ... # THEN ...
  • 35. Patch - TestCase class MessageSenderTests(unittest.TestCase): @patch.object(requests, 'post', autospec=True) def test_should_send_message(self, post_mock): pass @patch.object(requests, 'post', autospec=True) def test_should_not_catch_exception(self, post_mock): pass @patch.object(requests, 'post', autospec=True) class MessageSenderTests(unittest.TestCase): def test_should_send_message(self, post_mock): pass def test_should_not_catch_exception(self, post_mock): pass
  • 36. Patch - in setUp class MessageSenderTests(unittest.TestCase): def setUp(self): super().setUp() patcher = patch('requests.post') self.addCleanup(patcher.stop) self._post_mock = patcher.start() def test_should_send_message(self): # GIVEN self._post_mock.return_value = self._get_success_response() # WHEN ... # THEN ...
  • 37. Patch - environment variables class MessageSenderTests(unittest.TestCase): @patch.dict('os.environ', {'not_existing_key': 'some_value'}, clear=True) def test_should_override_environment_variables(self): self.assertEqual(os.environ, {'not_existing_key': 'some_value'})
  • 38. Summary Use mock when you can pass it Use patch when you can not pass mock