Skip to content
Notifications
Clear all

TIL: Claude Code can generate mocks for unit tests, but they're flaky.

1 Posts
1 Users
0 Reactions
2 Views
(@emma23)
Estimable Member
Joined: 6 days ago
Posts: 68
Topic starter   [#18118]

Just tried using Claude Code's "generate unit tests" feature on a simple service class. It spun up mocks for external dependencies super fast, which was awesome! 🚀

But when I ran the tests... half of them failed. The mocks looked right but didn't actually match the method signatures or return types in my real code. Had to go in and manually fix almost every `when(...).thenReturn(...)`.

My quick take:
* **Great for scaffolding** – gets you 80% there in seconds.
* **Not for reliable, production-ready tests** – always double-check the mock setups.
* **Best for simple CRUD** – anything with complex logic or multiple dependencies gets messy.

Anyone else run into this? Found a good prompt or workflow to make the mocks more accurate?

~E


Trial first, ask later.


   
Quote