when(dog).bark().thenReturn('meow')
self.assertRaises(DogsDoNotMeowException, veterinarian.inspect, dog)
verify(dog).bark()
As a contrast, the Mock framework emphasizes monkey-patching, e.G.
dog = Mock()
dog.bark.return_value = 'meow'
self.assertRaises(DogsDoNotMeowException, veterinarian.inspect, dog)
dog.bark.assert_called_with()
which is definitely straightforward but not as nice to read as the above.
when(terminal).render(any()).thenReturn(None)
terminal.render('fooo')
verify(terminal).render('foo')
Guess what the error message is? (Hint: it's not useful)
Wanted but not invoked: render('foo')
Yup. That's it.
terminal.render = Mock()
terminal.render('fooo')
terminal.render.assert_called_with('foo')
The error message is
AssertionError: Expected call: render('foo')
Actual call: render('fooo')
Mock has several other advantages over Mockito (like being able to mock open() statements
very easily).
YADT an Augmented Deployment Tool
Copyright (C) 2010-2016
Immobilien Scout GmbH
Licensed under GNU GPL v3
2016-05-11 10:48:37 +0000