Live data from Hacker News

Stepping down as Mockito maintainer after ten years

github.com

11–20 of 220 posts

Re: Stepping down as Mockito maintainer after ten years

#11
post #4

As someone who is not in the Java world, why does Java need a mocking library? Interface based polymorphism is not enough?

As someone who has been out of Java for close to 10 years now, you certainly could do without Mockito, but you'd be writing a lot of boiler plate code repetitively. There's also the case of third-party libraries that you don't control and Mockito has decent facilities for working with those, especially when you're working with a codebase that isn't pure DI and interfaces.

Re: Stepping down as Mockito maintainer after ten years

#12
post #4

As someone who is not in the Java world, why does Java need a mocking library? Interface based polymorphism is not enough?

The point is to let you create mocks without having to go through the whole polymorphism rigmarole, without forcing classes to define a separate interface or anything like that.

Re: Stepping down as Mockito maintainer after ten years

#13
post #4

As someone who is not in the Java world, why does Java need a mocking library? Interface based polymorphism is not enough?

Mocks make it easy to record and assert on method invocations. Additionally spys (instance mocks) are really useful when you need to forward to the real method or rely on some state.

At the moment I can't see anything Mokckito gives that you technically couldn't implement yourself via subclassing and overriding, but it'd be a lot of boilerplate to proxy things and record the arguments.

Re: Stepping down as Mockito maintainer after ten years

#14
post #4

As someone who is not in the Java world, why does Java need a mocking library? Interface based polymorphism is not enough?

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 verified if certain methods were invoked with certain arguments.

Re: Stepping down as Mockito maintainer after ten years

#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" not a satisfactory solution? Why do you even need a _dynamic_ agent; don't you know ahead of time exactly what agent you need when using Mockito?

> While I fully understand the reasons that developers enjoy the feature richness of Kotlin as a programming language, its underlying implementation has significant downsides for projects like Mockito. Quite frankly, it's not fun to deal with.

Why support Kotlin in the first place? If it's a pain to deal with, perhaps the Kotlin user base is better served by a Kotlin-specific mocking framework, maintained by people who enjoy working on those Kotlin-specific code paths?

Re: Stepping down as Mockito maintainer after ten years

#17
post #2

For those, like me, who haven't heard of it: Mockito is the "most popular mocking framework for Java".

It also translates to “small booger”, in Spanish, which always made me question who thought the name was a good idea over there.

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

Re: Stepping down as Mockito maintainer after ten years

#18
post #4

As someone who is not in the Java world, why does Java need a mocking library? Interface based polymorphism is not enough?

Mocks make it easy to record and assert on method invocations. Additionally spys (instance mocks) are really useful when you need to forward to the real method or rely on some state. At the moment I can't see anything Mokckito gives that you technically couldn't implement yourself via subclassing and overriding, but it'd be a lot of boilerplate to proxy things and record the arguments.

Subclasing and overriding is not a good idea. There is no compilation failure if you forget to override a function which can lead to flakey tests at best and prod data impact at worst.

Re: Stepping down as Mockito maintainer after ten years

#19

Earlier quoted context omitted.

Mocks make it easy to record and assert on method invocations. Additionally spys (instance mocks) are really useful when you need to forward to the real method or rely on some state. At the moment I can't see anything Mokckito gives that you technically couldn't implement yourself via subclassing and overriding, but it'd be a lot of boilerplate to proxy things and record the arguments.

Subclasing and overriding is not a good idea. There is no compilation failure if you forget to override a function which can lead to flakey tests at best and prod data impact at worst.

your test environment should not have the credentials to write to prod data. yiiiiikes!

Re: Stepping down as Mockito maintainer after ten years

#20
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…

Mockito was indeed a poor fit for Kotlin. MockK is the one. Except I suppose for shops that have projects that mix Java and Kotlin and already have a Mockito tests.
Post reply on HN