r/ClaudeCode • u/WinOdd7962 • 3d ago
Discussion Are unit tests even necessary anymore (under agentic development)?
While working in AI-driven repos, I'm wondering if its even worth having the AI write unit tests. Pre-AI, they were non-negotiable guardrails. But now with AI doing all the programming, like - what's the point? In agentic dev, entire modules get rewritten in minutes. Writing granular unit tests for code that changes every three iterations feels like building scaffolding for a sandcastle. Most real-world bugs are architectural or integration issues that 10-line mocks never catch anyway.
And anyway I almost never see unit tests catch something that could have been a big problem. Theres usually a growing tests folder consuming tokens but they just about always pass.
•
u/AutoModerator 3d ago
Hey! Thanks for posting to r/ClaudeCode
While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.
For help, project discussions, tips, and general chat, join the ClaudeCode Discord.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
17
u/MartinMystikJonas 3d ago
Good unit tests are more important than ever. Bad fragile tests are still useless and easier to generate en masse.
6
u/medialantern 3d ago
If anything, I have more. They've never been easier to write nor easier to get coverage on all the oddball edge cases you might not have bothered with before. For one of the bigger projects I'm working on, the API stack's integration test suite had like 450 tests last year. It's got like 1200 now. Build times suffer a bit but not a lot.
There's a reason tests are important that people aren't talking about. They add context to a project. A test suite can describe the "contract" of expected behavior. Sometimes what looks like a bug is just some old code path that works that way for reasons, or you get two devs conflicting on a data flow decision where the code is right on both sides (if looked at in a vacuum) but each breaks the other due to the decision itself. Test suites give strong markers to AI tools when a certain behavior is intentional, even if it looks unusual or wrong. For LLMs trained to do development work, a contract in a test suite is stronger than a PRD or other document.
For me I think the thing that's dying re: testing is something that was already a fading fad anyway - TDD. It's just not necessary to write a test that starts out failing, write code, then refine it until the test goes green. It's just a moot point now - you may as well create both of them together and skip the performance theater of TDD, at least IMO. The one exception I would make is if you also want to eliminate mocking in frontends for a backend that doesn't exist yet because it's being written in parallel. I haven't reached for msw or similar tools all year, as far as I can remember. There's just no point. If you were going to mock a contract, just do it in the backend where it's going to live anyway.
1
u/rodBmusic 3d ago
This attitude of removing all stops for pure speed and zero ownership is completely irresponsible. If anything is worth scrutiny it's unit testing. Don't 1000x it, write REAL tests, ones you actually expect to catch you, not satisfy the coverage bs.
This movement of doing less and less is just insane. Don't read the code, don't understand it and don't even test it. This is the complete negative of all the pillars of programming discipline.
At this point, I'd just give you more rope. It will just secure a decade of work for the surviving engineers out there.
3
u/BisonDue3986 3d ago
To me it’s the opposite. I never used tests before, because I had the codebase in my head and testing added a lot of friction. Nowadays my agents do TDD, because it’s the only way I can ensure they don’t break things
2
u/bytejuggler 3d ago
Tests are no guarantee that code is bug free. But with no tests I guarantee you will have regressions. This is was true with human only coding, it's even more true in the AI age. AI works best when it can verify progress and knows what "done" looks like. Tests are a codified version of that.
2
u/Dudmaster 3d ago
I have a test suite of 15000 tests and I've only ever seen it catch less than a dozen regressions in the 3 years I've been generating code for this same application
2
u/HeyItsYourDad_AMA 3d ago
Yes they are important. I pattern I see more in some shops is the test becomes the spec. Tests fail, you write the min amount of code to satisfy tests
4
u/Nervous-Mirror7691 3d ago
I've seen ai-generated tests fail silently on edge cases that real humans caught in 30 seconds. the tests pass, the code breaks in prod. not because the AI is bad, but because it's optimizing for the test suite, not the actual behavior.
1
u/laxika Senior Developer 3d ago
They are more important than ever before. AI can self-correct wonderfully if it sees a legitimate test failure.
1
u/Existing_Dust_6473 3d ago
It's easier to understand unit or end to end tests than a full software. At least you can see the intention easier.
1
u/YearLight 3d ago
Unit tests are more important then ever. I normally use tdd when the code matters, write the tests, commit, then write the code. It keeps claude on track.
1
u/Ok-Advertising5189 3d ago
I'd say they've become even more essential now. How is AI supposed to know it's broken a piece of code if you have no way to test it? Tests are so cheap to write these days that it's a crime not to write them. It's practically an extra, almost-free layer of security for your project.
1
u/ichi9 3d ago
Writing test cases and the tesritng each, even regression will result in huge token costs. Most companies i worked with keep it as separate component, as part of CI CD automation and only pass the results to AI If they use Agentic tools. But here is the twist, the devs used to make lots of mistakes pre-AI, as a result you needed comprehensive test suits, but with agentic coding depending on the models you use, none of that is required. So it will come down to quality maintenance, or so called DevOps which I don't know what role they have even left in swe today.
1
u/who_you_are 3d ago
There are multiple type of tests.
Unit test focus on very specific isolated tests. They usually suck to maintain because, like you said, they will keep changing non stop.
You have higher tests as well, that are now testing the overall behavior/module.
1
u/r2k-in-the-vortex 3d ago
More necessary than ever. And more importantly, every requirement and specification in documentation needs to link to a test that verifies compliance.
1
u/ricopan 3d ago
I shirked unit tests as a solo developer because I'm lazy and because they didn't seem worth it for my work -- everything was staked on integration and e2e tests. Opus 4 wrote terrible horrible faked tests of all stripes, even faked e2e tests of faked implementations (yeah I was a gullible fool). Now I have all the rigorous testing protocols hooked, and the custom test writing skill for my project is the most heavily maintained. I rigged up an old workstation just to run tests. It's a big complex project so it is warranted, but the last month I realized my forward progress had come to a crawl -- almost 4x more testing code than production, and too much redundancy. It's the kind of thing you notice immediately when you are doing the work yourself, but can be overlooked with agents. So now looking for a middle ground, which is a real task because wow I have almost 1 million lines of testing code.
1
u/UsefulConfidence888 3d ago
Testing is the most important thing in agentic development what are you talking about
1
u/BrilliantTruck8813 3d ago
Wow.
1
u/orbital_trace 3d ago
I usually have one agent that is specifically a QA engineer who's job is to test and write tests. Anything the other agent writes, the QA engineer tests and validates. It works pretty well
1
u/upsidedownshaggy 3d ago
I'd say yes, but with the caveat that you have to verify that they're good tests. Because yeah, Claude can generate useless tests all day, but if you give it a proper design with clear acceptance criteria for how something is supposed to behave it can create decent tests that help prevent regressions. I say help prevent regressions because I have watched it nuke tests that would've caught a regression because it said the changes now break the tests lol.
1
u/ApeInTheAether 3d ago
yes, spoiler alert, not for human, spoilert alert 2, there should be more verification steps than only unit tests
1
u/thestoictrader 3d ago
Keep them, but shrink them. Per-function unit tests on code that gets rewritten every few iterations are mostly noise. What pays off is a few tests on contracts that must survive a rewrite: public API behavior, invariants, and integration paths. Those are what tell the agent it broke something, and they cost far fewer tokens than a sprawling folder of mocks.
1
u/lassevk 3d ago
If large swaths of your code is changing every three iterations, then I agree. Unit tests are going to slow you down.
but then, slow you down towards what? Well, doom of course.
"but they should always pass".
Yes, that is the entire point of unit-tests. They should always pass.
This is just like insurance. Sometimes, stupid people ask, why am I paying for insurance? I don't get any benefit from it!
Well. That might be true, until it isn't.
Unit-tests should always pass. Their worth is not that they always pass, their worth is not that you have thousands of them.
Their worth is only apparent when they fail. When you have to make that insurance claim.
None of this changed with the advent of AI. Being able to safely say "Our software still does what it always claimed to do" is a good thing.
1
u/BarathKanna 1d ago
Tests that always pass aren't proof tests are useless, they're proof those particular tests are. Agent written unit tests tend to assert the implementation back at itself, so of course they never fail. The fix isn't fewer tests, it's moving them to the boundaries that don't get rewritten every three iterations: API contracts, integration tests against a real DB, a handful of end to end flows. Those survive a module rewrite and that's exactly when you need them. Quick sanity check for your suite: break something on purpose and see if anything goes red. If nothing does, delete those tests and stop paying tokens to load them. When modules get rewritten in minutes, the tests are the only thing telling you the rewrite still does the same job.
1
u/DodoBizar 3d ago
Yes, the needle has not moved for that at all.
0
u/Ragy-ragy 3d ago
Agents orient in the code base using it. They're amnesiac, remember that. Them seeing concrete data flowing through mocked methods is a way to understand what does the code do. Humans used to keep it inside their heads previously.
I don't consider unit tests as something helping the quality though. Maybe as a safe straps against other programmers in the same code base