News for hackers. Stuff that matters.
Re:Mockito 2.1.0 by carrja99 on Monday October 03, 2016 @09:31AM (#12627287)
After journeying through many languages since my long time with Java that ended in 2011 I have to say I have yet found a mock object framework in other languages that match the expressiveness that Mockito did. Python's mock has the least memorable API I have ever worked with. :-(
Re:Mockito 2.1.0 by dom0 on Monday October 03, 2016 @09:37AM (#12627333)
This is because using Mocks in a language like Python is a bit awkward and unnatural in itself... if you look at the way tests are usually written, there is just little need for it. That's also the reason why only recently unittest.mock was added in the first place.
Re:Mockito 2.1.0 by samcal on Monday October 03, 2016 @10:46AM (#12627753)
Can you elaborate on this? What is the correct way to test external services that may have side effects in Python?
Re:Mockito 2.1.0 by bebop on Monday October 03, 2016 @12:18PM (#12628737)
I think maybe because there is no type checking in Python. This makes it more trivial to have objects that quack like a duck, without the need to explicitly create a class that conforms to an interface.
Re:Mockito 2.1.0 by LgWoodenBadger on Monday October 03, 2016 @12:43PM (#12628998)
FWIW, you don't do that with Mockito either, in Java land.

Mockito will happily use the existing type definition of your dependency, provided that the class declaration is not final (i.e. can't be extended).

Re:Mockito 2.1.0 by raphw on Monday October 03, 2016 @04:24PM (#12631011)
This is actually not a requirement anymore. Mockito 2 can mock final types and methods.
Re:Mockito 2.1.0 by dom0 on Monday October 03, 2016 @02:10PM (#12629849)
When it comes to external dependencies there are mostly two ways this is dealt with:

- Often there is a backend-like structure, and you got a dummy backend of sorts. Django's mail sending is a typical example of this: https://docs.djangoproject.com/en/1.10/topics/email/#in-memo...

- Another commonly seen way is that there is a backend of sorts passed around and can be injected with little hassle from the tests. Often you'll see what boils down to a Mock, just written by hand, because it tends to be little hassle, and often results in quite clear testing code.

Generating types on the fly using mocking and then doing somewhat awkward indirect assertions is by comparison a bit convoluted and less clear.

Re:Mockito 2.1.0 by samcal on Tuesday October 04, 2016 @03:04PM (#12638345)
Ah, that's where I was confused. I would call both of those solutions mocks.
Re:Mockito 2.1.0 by whoisthemachine on Monday October 03, 2016 @01:44PM (#12629599)
Moq [0] in C# is much better imo.

[0]: https://github.com/moq/moq4