logoalt Hacker News

BlackFlyyesterday at 10:18 PM1 replyview on HN

An anonymous inner class is also ephemeral, declarative, inline, capable of extending as well as implementing, and readily readable. What it isn't is terse.

Mocking's killer feature is the ability to partially implement/extend by having some default that makes some sense in a testing situation and is easily instantiable without calling a super constructor.

Magicmock in python is the single best mocking library though, too many times have I really wanted mockito to also default to returning a mock instead of null.


Replies

davnicwilyesterday at 11:07 PM

> What it isn't is terse

Yeah, it's funny, I'm often arguing in the corner of being verbose in the name of plain-ness and greater simplicity.

I realise it's subjective, but this is one of the rare cases where I think the opposite is true, and using the 'magic' thing that shortcuts language primitives in a sort-of DSL is actually the better choice.

It's dumb, it's one or two lines, it says what it does, there's almost zero diversion. Sure you can do it by other means but I think the (what I will claim is) 'truly' inline style code of Mockito is actually a material value add in readability & grokability if you're just trying to debug a failing test you haven't seen in ages, which is basically the usecase I have in mind whenever writing test code.

show 1 reply