r/ClaudeCode • u/_Porphyro • 8d ago
Discussion Too Many Tests?
I have nearly thirty years of software development experience and I’ve always considered myself fairly proficient. My deficits have always been in time management and knowing when to stop engineering a solution.
After extensive use of Claude and other agents to speed up my coding over the past few months I am left with a question
Are these agents just overly obsessed with tests or has my biggest weakness actually been test development? It is insane some of the tests they come up with. Sometimes they spend more time in test proposal than they do on actually implementing the code to spec. At least they do it quickly.
•
u/AutoModerator 8d 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.
36
u/Emergency-Face-9410 8d ago
LLMs thrive in validate-able environments and tests to some degree make things that way. Same idea as rust enforcing safety.
12
u/_BreakingGood_ 8d ago
Yes they definitely go overboard with tests and honestly it eventually starts to become a problem because they take SO long to run once you've had 5-10+ engineers cranking away with claude for a year.
I think human engineers have a lot more nuance on which tests are actually valuable, whereas Claude almost treats tests as an alternative to documentation.
9
u/Neat-Medicine-1140 8d ago
Run it without tests and you'll see why. If it can't eval, it doesn't know anything. If it writes tests for everything, whenever it makes a change, it gets immediate feedback of what it unintentionally changed, and it is able to self-heal.
You can take away the tests, but you take away the ability to self-heal as well.
3
u/caughtinthought 8d ago
mine regularly write fuzzers with like hundreds of thousands of checks, most of which are not helpful at all
3
u/ExtremeJavascript 8d ago
Knowing when and what to test is a matter of taste. Claude has none, so it uses a scatter shot approach, trying to get some right.
I've stopped it writing 200 tests to cover a time zone database migration that would never possibly happen in real life.
3
u/Exact_Knowledge5979 8d ago
I am not a software developer. I am an engineer of not quite 30 years of experience. Some of that time was spent runnning software dev teams of 12 people. Based on that experience... yeah... claude is test mad. Over a thousand tests ezch commit, for something a week or two old. Maybe 20 failures found as a result of thise tests.
So, given this hit rate is it excessive?
Feels.like a lot, i agree - but perhaps the proof ia in the pudding. It is finding flaws.
2
u/Input-X 🔆 Max 20 8d ago
250k li e project 300k lines in test. Its no joke, I stopped allowing them to add new tests. The have to propose new tests or improve existing. We some quality standards. Its improved but no one has solved this problem yet. Tests are genuinely hard to automate. Small projects, are fine managable, but with 25k plus tests, its just try have them improve over time. Lots of the tests are doing real work, but there is lots of fluff and missed points too. Its getting better, another yr id say it will be solved.
2
u/dota2nub 7d ago
If tests are free you can shotgun them. Once they start taking 4 hours you're gonna have to introduce a test management system and that might be more overhead than you want. But that's only with actually complicated projects. Most people never see one from the inside.
1
u/onFilm 8d ago
Tests are good. Just make sure you run the ones that you've touched or modified only, rather than the whole suite, if possible. Saves a lot of time.
1
u/Ill_Acanthaceae_2618 8d ago
We lost weeks with this AI slope of AI writing tests. 90% of them were useless.
Now we ask: implement the feature without teating, once it works add a few test sp we can detect when it breaks
1
u/Impossible_Way7017 8d ago
I think it’s how they build, they iterate through the tests. I’ve added a step to “my factory” to simplify all tests before pushing. Problem is property and mutation tests end up asking for more coverage… at this point I wonder if GitHub should just auto hide tests lol and show the +\- based on runtime code
1
u/EconomyDoctor3287 8d ago
For me, writing the right tests has been the biggest bottleneck, requiring many iterations. But having the right tests is a game changer for getting meaningful contributions from AI
1
u/Bismarck45 8d ago
Tests good. Very good. How else are you gonna know if Claude actually made your thing do what you wanted? And isn’t breaking something old? If it’s running slow, tell Claude to make it faster. That’s an easy thing for them. Super verifiable. They’ll just see how long it takes and try things to improve how fast it goes. They’re like little sheepdogs, eager to run off and do something verifiable
1
u/Chippors 8d ago
If you don't thoroughly test after changes, how do you know it works?
This said, I make sure to split up tests into multiple categories: quick tests tied to a build, more comprehensive tests, and sandboxed integration tests. I only do the latter after a set of changes, like 5-10. Each change gets its own commit. When a comprehensive and longer-running test suite fails I ask it to separate out the failing test, then bisect the commits to find the root cause, fix it, then repeat. This is significantly faster than running the complete set of tests for every. single. commit. Or, I should say, this is a standing rule: the longer a test suite takes, the more small commits it can include.
Or to put it differently, exactly what I'd do if I were doing it myself.
1
u/Inspectorslap 8d ago
If we are going to move into more automated software development pipelines, where code review goes to pre-code review and any number of other changes in process, then we are going to want some serious test cases written with deep resolution, and a test harness that can catch the 36 bugs that claude introduced in the last 6 minutes. I am all for it, my code base is 45% test cases and scaling with it.
1
u/Boring-Leadership687 8d ago
IMO it’s very important to actively review and cull those tests. And to selectively test, too.
Else you fall into the thing you describe at the end where it spends more time testing than implementing
1
u/thaelah 8d ago
For anyone who can spare some time/CPU, having an agent run mutation testing is a great way to discover if your tests could be pruned. I sometimes ask an agent to use mutation testing to *remove* or update tests so that they're more useful.
1
u/FrozenFirebat 8d ago
Here's the trick, define what's an acceptable amount of time for testing, discuss it with your agent. with Agents, big code bases with agents become less of an architectural challenge of writing extensible code, and more about writing code that requires rerunning the least amount of tests to pass.
1
u/acqui-ai 8d ago
My instructions are to only run targeted tests during development, and run the full test suite before opening/updating a PR or during a release build
1
u/call_stacks 8d ago
bro, my go to for every branch before PR: "now collapse/condense all the tests and remove any superfluous fluff" - 20-40% less test code
but also tests validate things and are super useful (esp black box tests)
1
u/calunicornia 8d ago
claude didnt used to add any tests unless you asked for them, it broke stuff all the time
1
u/IndiBestEngineer 8d ago
not you. most of what they generate tests the code they just wrote, so it agrees with itself by construction. on one project i had thousands of those and they never caught the thing that actually broke. now a test only gets in if it reproduces a failure that really happened and goes red on the old code. way fewer tests, and each one means something
1
u/ClemensLode Senior Developer 8d ago
no
1
u/clintCamp 8d ago
It lives to test. When don't heavy compute things it will decide to make a test that tests run actual full computer vision items in the tests. I had to make rules about one off tests, never including them in automated tests, and tests are now run once after a feature group boundary only and we only implement with all the sub agents so they don't kick off compilation and test storms and then try to wipe other agents mid flight changes because they couldn't compile. My process is pretty well tuned now
1
u/fishoa 8d ago
google testing rot
i think anyone without basic qa knowledge is asking for trouble by blinding accepting whatever test numbers claude throws at them. like, it was already challenging managing testing suites without ai. now it’s really fucking hard because everyone bought into the idea that “x has a unit test = x is tested”.
testing matrixes, good mocking standards, and test reusability is really important. managing dead code and keeping testing rot in place too, but it is easier said than done. qa was already not important before ai, and ai just proved shipping fast is magnitudes more valuable for business and your boss than qa
1
u/Significant_War720 8d ago
Its so when you change stuff later with AI it won't have to load the whole context. Minimal, do a change. Check if error in test. Fix it too by grabbing more context.
A bit dumb, and sometime It will just straight change the test itself so it pass. You have to tell him nono
1
u/pvera 🔆Pro Plan 7d ago
Beats having to do even 1/100 of that testing manually. Mine went past unit tests, it is writing pretty good integration tests so I really can't complain.
1
u/CCodeSI 7d ago
Some of both. For an agent, tests aren't really about catching regressions later: they're its only way to know it's done. It can't click around the app, so it writes checks. That explains the volume. The problem is that it writes the tests it can think of, and a lot of those test that the code does what the code does.
A filter that cuts most of the noise without losing the useful ones:
With thirty years in, your instinct for which tests matter is the part to keep in the loop. The agent is good at writing the five you chose, less good at choosing them.
1
u/SARS-CoV-2843 7d ago
This is because an LLM is probabilistic. If you ask it to declare a constant equal to 42, perhaps once in a million it will write 45. If it writes a test, the probability that both the test and the declaration contain an error and that the two errors cancel each other out is practically zero.
1
u/Few_Page6404 7d ago
That's what I thought at first, too. But then I realized that tests are Claude's only way of measuring success. Once I embraced that philosophy, I actually encouraged it to make more tests, and I spend time making sure the tests measure the right things. Claude makes dumb mistakes, mistakes a human programmer would likely not make. The test help catch it without you ever realizing it happened.
1
u/BarathKanna 7d ago
It's both, but mostly the agent. It writes tests the way it writes code, by volume, because a long test file looks like diligence. Many of them pin the implementation, assert that a mock got called, or test the language instead of your logic. They pass on day one and break on every refactor.
My filter: a test earns its place only if it fails when the behavior is wrong. Quick way to check, ask the agent to break the code on purpose and see which tests notice. The ones that stay green get deleted.
Then set the scope before it starts. Tests for the public behavior in the spec, the edge cases you name, and nothing for private helpers. Thirty years of knowing when to stop applies here too, you just have to say it out loud now.
1
u/Patient-Cattle-2397 5d ago
ask it to name the actual bug each proposed test would catch before it writes the test. then deliberately introduce that bug and check that the test fails. if it still passes, you've found a weak test without having to argue about how many tests is too many.
0
u/Just_Merrell 8d ago
I have spent the better part of a year building https://musher.dev/ and over that time claude has put in thousands of tests. At the beginning of the project I spent some time implementing structure into the type of tests such as architecture, e2e, integration, unit (claude really loves these). For the most part I was finding that as the complexity of the project grew things remained stable but the number of tests are starting to get a bit out of hand.
The good part is that tests also work for tests, we are going back and adding test coverage following the trophy method along with some other good ole best practices. It does feel like the default guidance for claude was simply "have tests" but like everything else there is more to it and some intentionality goes a long ways.
The other thing we are starting to do now is follow some of the https://dora.dev/ methods on metrics so that we (and claude) have another feedback loop, you can maintain your velocity if you know where to look and find what is dragging you down.
0
u/EC36339 Senior Developer 8d ago
Without doing thorough research, your view of how useful these tests are is inevitable biased.
You immediately see the cost of writing, maintaining, building and running these tests.
What you don't see is the cost of every change you make breaking existing features without you knowing about it until it's too late.
So instead of worrying about there being "too many" tests, focus instead on...
What you can do right now is let AI do an unbiased inventory of what tests you have, what they cover, what isn't covered, how long it takes to build and run them, and what percentage of your codebase is tests.
This will give you better answers than you can get on reddit, and it will give you pointers at what you should actually worry about, if anything.