logoalt Hacker News

davnicwilyesterday at 11:07 PM1 replyview on HN

> 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.


Replies

BlackFlytoday at 10:41 AM

I cannot put my finger on it exactly either. I also often find the mocking DSL the better choice in tests.

But when there are many tests where I instantiate a test fixture and return it from a mock when the method is called, I start to think that an in memory stub would have been less code duplication and boilerplate... When some code is refactored to use findByName instead of findById and a ton of tests fail because the mock knows too much implementation detail then I know it should have been an in memory stub implementation all along.