# Mockito

19 Hacker News commenters recommended Mockito and 13 criticized it, November 2025 to November 2026. It was recommended in 3 of 13 months; owners who said how long report a median of 4 years (4 owners).

**Verdict:** People recommend it as a Java mocking library that works well for testing code that does not use dependency injection, and many call it good enough for most cases. Critics warn that it encourages brittle tests and lazy design.

## Why people recommend it

- Works for code without dependency injection (3 comments): "Mockito has decent facilities for working with those, especially when you're working with a codebase that isn't pure DI and interfaces." ([source](https://news.ycombinator.com/item?id=46414677)) "Mockito allows one to write mocks in tests for code that doesn't use dependency injection" ([source](https://news.ycombinator.com/item?id=46414647)) "Mockito, in every case I had to use it, was a last resort because a third party library didnt lend itself to mocking" ([source](https://news.ycombinator.com/item?id=46416860))
- Good enough for most testing cases (3 comments): "I've been using Mockito for about 4 years, all in Kotlin. I always found it to be "plenty good" for like 99% of the cases I needed it" ([source](https://news.ycombinator.com/item?id=46417017)) ""plenty good" for like 99% of the cases I needed it" ([source](https://news.ycombinator.com/item?id=46415358)) "I like Mockito, it's useful" ([source](https://news.ycombinator.com/item?id=46417180))
- Useful when third-party libraries resist mocking (2 comments): "Mockito, in every case I had to use it, was a last resort because a third party library didnt lend itself to mocking" ([source](https://news.ycombinator.com/item?id=46416860)) "The only way I was able to pull that off was using mocking" ([source](https://news.ycombinator.com/item?id=46416938))

## What people warn about

- Encourages bad habits and brittle tests (4 comments): "Mocking encourages bad habits and a false sense of security." ([source](https://news.ycombinator.com/item?id=46415651)) "tests depending on mocking are far more brittle" ([source](https://news.ycombinator.com/item?id=46415793)) "Mockito swoops in and prevents you from having that epiphany, by making it easier to keep doing things the stupid way." ([source](https://news.ycombinator.com/item?id=46416064))
- Overused for pointless unit tests (2 comments): "Usually it is used for pointless unit tests of simple intermediary layers to test if call is delegated correctly" ([source](https://news.ycombinator.com/item?id=46419264)) "It allows you to mock the whole universe so it becomes a hammer instead of nicely designed functions, interfaces." ([source](https://news.ycombinator.com/item?id=46417967))

## Alternatives hackers recommend

- [cargo-nextest](https://hackerapproved.com/p/cargo-nextest.md): 18 recommend
- [Vitest](https://hackerapproved.com/p/vitest.md): 17 recommend
- [Testcontainers](https://hackerapproved.com/p/testcontainers.md): 14 recommend
- [pytest](https://hackerapproved.com/p/pytest.md): 12 recommend
- [Cucumber](https://hackerapproved.com/p/cucumber.md): 9 recommend

## Cite as

Hacker Approved, "Mockito", https://hackerapproved.com/p/mockito/ (counts from 1,795,640 Hacker News comments, November 2025 to November 2026).
