Live data from Hacker News

Stepping down as Mockito maintainer after ten years

github.com

161–170 of 220 posts

Re: Stepping down as Mockito maintainer after ten years

#161

Earlier quoted context omitted.

You wrap whole 3rd party dependency in an adapter.

That's a lot of upfront work and maintenance, not to mention the friction of needing to mentally translate every occurrence of OurFooAdapter to Foo in order to find documentation.

Yeah, well, good code takes some thought to produce. More news at 11.

Re: Stepping down as Mockito maintainer after ten years

#162
post #70

Earlier quoted context omitted.

90% of the time (or more): you don't. The real thing is perfectly fine in a test with the right setup. Fileio is fast, I just need a test file in a tempdir. databases are fast, I just need an easy way to settup my schema. Sometimes I need the isolation but normally I do not.

Well, no - you don't. What you're describing is a very limited subset of testing, which presumably is fine for the projects you work on, but that experience does not generalise well. Integration testing is of course useful, but generally one would want to create unit tests for every part of the code, and by definition it's not a unit test if hits multiple parts of the code simultaneously. Apart from that, databases a…

> Using mocks properly is a sign of a well-factored codebase.

Well-factored codebase doesn’t need mocks.

Re: Stepping down as Mockito maintainer after ten years

#163
post #100

Earlier quoted context omitted.

I worked on a project where a dev wanted to mock out the database in tests "for performance, because the database is slow". I almost lost my shit. Even funnier, this was all hypothetical and yet taken as gospel. We hadn't even written the tests yet, so it was impossible to say whether they were slow or not. Nothing had been measured, no performance budget had been defined, no prototype of the supposedly slow tests ha…

> I almost lost my shit. Hopefully one day you'll back at that, and realise what an immature attitude that was.

Hopefully one day I won’t have to deal with clowns like you.

Re: Stepping down as Mockito maintainer after ten years

#164

Earlier quoted context omitted.

I'm not sure I understand. "The solution is to have dummy versions of services and interfaces that have minimal correct behavior". That's mocks in a nutshell. What other way would you use mocks?

There are different kinds of mocks. Check function XYZ is called, return abc when XYZ is called etc are the bad kind that people were bit badly by. The good kind are a minimally correct fake implementation that doesn't really need any mocking library to build. Tests should not be brittle and rigidly restate the order of function calls and expected responses. That's a whole lot of ceremony that doesn't really add conf…

The second way is usually referring to as "fakes", which are not a type of mocks but a (better) alternative to mocks.

Re: Stepping down as Mockito maintainer after ten years

#165
post #85

Earlier quoted context omitted.

Mockito uses declarative matching style of specifying what should be mocked. You don't need to implement or even stub all of interface methods since Mockito can do it itself. It may be extremely concise. For example, interfaces may have tens methods or even more, but only one method is needed (say, java.sql.ResultSet). And finally probably the most important thing, interaction with mocks is recorded and then can be v…

That’s the seductive power of mocking - you get a test up and running quickly. The benefit to the initial test writer is significant. The cost is the pain - sometimes nightmarish - for other contributors to the code base since tests depending on mocking are far more brittle. Someone changes code to check if the ResultSet is empty before further processing and a large number of your mock based tests break as the origi…

Jumping ahead to the comments below: obviously, I mentioned `java.sql.ResultSet` only as an example of an extremely massive interface. But if someone starts building theories based on what is left unsaid in the example for those from outside the Java world, one could, for instance, assume that such brittle tests are simply poorly written, or that they fail to mitigate Mockito's default behavior.

In my view, one of the biggest mistakes when working with Mockito is relying on answers that return default values even when a method call has not been explicitly described, treating this as some kind of "default implementation". Instead, I prefer to explicitly forbid such behavior by throwing an `AssertionError` from the default answer. Then, if we really take "one method" literally, I explicitly state that `next()` must return `false`, clearly declaring my intent that I have implemented tests based on exactly this described behavior, which in practice most often boils down to a fluent-style list of explicitly expected interactions. Recording interactions is also critically important.

How many methods does `ResultSet` have today? 150? 200? As a Mockito user, I don't care.

Re: Stepping down as Mockito maintainer after ten years

#166
post #16

I respect the maintainer's decision, but I don't understand the justification. > but when it was communicated with Mockito I perceived it as "Mockito is holding the JVM ecosystem back by using dynamic attachment, please switch immediately and figure it out on your own". Who did the communication? Why is dynamic attachment through a flag a problem, and what was the solution? Why is "enable a flag when running tests" n…

> Why support Kotlin in the first place? Some complexities are discovered along the way, people don't know everything when they start. They could also drop the support after some time, but then it would have created other set of problems for adoption and trustworthiness of the project.

Sounds like a problem that the Mockito team created for themselves, and like a problem only they can solve.

Re: Stepping down as Mockito maintainer after ten years

#167
post #125

Earlier quoted context omitted.

Why? Every name you pick is likely to be weird in one language or another. Mockito does one thing well as a name, and that is hinting strongly at what it is (a mocking library).

Wasn't it a riff on "Mojito" which was a popular drink at the time?

Mojitos aren't popular anymore?!

Re: Stepping down as Mockito maintainer after ten years

#168
post #95
post #80

Earlier quoted context omitted.

Is it anger? The agent thing maybe. The other two points seem to boil down to: 1. Kotlin is a hack and 2. Rust is more fun. Pretty understandable why one would simply want to move on to greener pastures.

I'm not sure Kotlin is a hack, but it's growth is directly related to Java not being able to deliver on simple features that would help the day to day lives of developers. So I also can't blame anyone for moving on from the language. I get frustrated with it all the time, especially when Kotlin shows that some feature could work perfectly fine. Here are some examples that have hit the graveyard: It's been 2 years sin…

Sure there are pain points in Java, but I definitely wouldn't want the language to introduce 15 new features each having only a tiny benefit.

Based on your other comment you prefer "fat" languages like kotlin and C# - and that's fair. I find languages with less, but more powerful features far more elegant and while Java has its fair share of historic warts, modern additions are made in a very smart way.

E.g. switch expressions seamlessly support sum and product types, meanwhile kotlin's `when` really is just syntactic sugar.

All in all, with too many features you have to support and understand the complete matrix of their interactions as well, and that gets complicated quickly. And Kotlin is growing towards that.

Re: Stepping down as Mockito maintainer after ten years

#169
post #80

Earlier quoted context omitted.

Is it anger? The agent thing maybe. The other two points seem to boil down to: 1. Kotlin is a hack and 2. Rust is more fun. Pretty understandable why one would simply want to move on to greener pastures.

Kotlin is a thoughtful language that is a joy to write. Java was stagnant and ripe for being kicked off the top. Scala was the hack that showed why Java was starting to suck but Scala suffered from no direction. Every single idea a PhD ever had was implemented in the language with no thought other than it seems cool to be able to do that too. Which is why all the Scala codebases fell apart, because you could write an…

> Scala was the hack

Well, I absolutely disagree with this take. Scala actually builds on top of a couple of its powerful primitives. Especially Scala 3 is a beautiful language.

Re: Stepping down as Mockito maintainer after ten years

#170
post #159

Earlier quoted context omitted.

> Someone changes code to check if the ResultSet is empty before further processing and a large number of your mock based tests break as the original test author will only have mocked enough of the class to support the current implementation. So this change doesn't allow an empty result set, something that is no longer allowed by the new implementation but was allowed previously. Isn't that the sort of breaking chang…

I used ResultSet because the comment above mentioned it. A clearer example of what I’m talking about might be say you replace “x.size() > 0” with “!x.isEmpty()” when x is a mocked instance of class X. If tests (authored by someone else) break, I now have to figure out whether the breakage is due to the fact that not enough behavior was mocked or whether I have inadvertently broken something. Maybe it’s actually impor…

What is the alternative? If you write a complete implementation of an interface for test purposes, can you actually be certain that your version of x.isEmpty() behaves as the actual method? If it has not been used before, can you trust that a green test is valid without manually checking it?

When I use mocking, I try to always use real objects as return values. So if I mock a repository method, like userRepository.search(...) I would return an actual list and not a mocked object. This has worked well for me. If I actually need to test the db query itself, I use a real db

Post reply on HN