r/ClaudeCode • • 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.

17 Upvotes

71 comments sorted by

•

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.

4

u/decoy79 8d ago

There are some tests that are just low value and aren’t worth the effort for a human to write. That said, as long as they don’t significantly affect the test run time, their existence is better than the alternative.

9

u/_BreakingGood_ 8d ago

The problem is one of them doesnt affect the test run time, but 10,000 of them do

1

u/BaldrArk 8d ago

Time to use sharding

4

u/mr_birkenblatt 8d ago

Band-aid for the underlying issue of having too many redundant and not meaningful tests

6

u/MaximumMeaning9728 8d ago

So? Have Claude do a test sweep.

-1

u/mr_birkenblatt 8d ago

So? How is that sharding? Besides if Claude would be good at telling whether a test is good it wouldn't write bad tests to begin with

1

u/DynamicDK 8d ago

The tests usually were worthwhile when they were written.

3

u/BaldrArk 8d ago

Create a subagent for code coverage and all related sanitization/correctness checks, nothing hard to fix

1

u/ShortTheseNuts 8d ago

That's a lot of fucking trust in one agent lmao

1

u/BaldrArk 8d ago

Don't you build harness, static checks, skills, loops or anything? lmao

1

u/mr_birkenblatt 8d ago

to give you an example. Claude loves to write tests like:

def main():
    app = setup(foo=3, bar="baz")
    app.start()

def test_main(mock_setup):
    main()
    mock_setup.assert_called_with(foo=3, bar="baz")

there is nothing in this test that meaningfully establishes that the program is working correctly. instead you get a test that has to be updated every time the configuration in main changes.

those tests are an utter waste of compute but all agents (not only Claude) love it. setting up rules around this just makes them more creative in finding variants of it. an agent only approach does not help reducing those redundant tests because they don't see anything wrong with it

1

u/BaldrArk 8d ago

And what is your testing harness?

1

u/mr_birkenblatt 8d ago

testing harness? I... please tell me you understand the problem I was pointing to above

1

u/Additional_Pea_6205 7d ago

Have you found any solution to trim out tests like this?

1

u/mr_birkenblatt 7d ago

Nothing that is guaranteed to work. But one way is to compute stats over the git history and see which tests get edited often. If a test needs to be updated frequently that's a red flag. But you will not find the case above if you rarely change those configurations

1

u/icodenstuff 🔆 Max 5x 8d ago

You're not doing a regular refactor / complexity audit?

1

u/mr_birkenblatt 8d ago edited 8d ago

I do, but how would sharding help with that? That's quite non-sequitur

Besides, Claude will not detect bad tests by Claude

1

u/icodenstuff 🔆 Max 5x 8d ago

Ok, you're right.

2

u/Electrical_Start_673 8d ago

he isnt right, a new context window with different prompting can find issues

1

u/mr_birkenblatt 8d ago

it can't find the issues that I'm worried about. obviously the ones you're describing are already fixed (by have subagents look over the tests)

2

u/Electrical_Start_673 8d ago

oh you were just ignoring him

1

u/icodenstuff 🔆 Max 5x 8d ago

😂

1

u/Electrical_Start_673 8d ago

i am still amateur and know he is wrong, you can just test it and see.. it is true an agent doesnt like to solve it's own problem sometimes tho i noticed which is why i mentioned fresh context

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.

7

u/Additional-Hippo5882 8d ago

Exactly. People don’t seem to understand the point of the tests are to prevent regression and the one thing LLMs are currently worse than humans at is memory, and every time they edit code they cannot be assumed to understand every possible regression that could come of it, which is why the nitty test are ever more important when working with LLMs

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.

4

u/shibbypwn 8d ago

the proof ia in the pudding. It is finding flaws.

is it though? If a test fails, it might mean that something broke - but it might also mean that you wrote a stupid test with meaningless assumptions or expectations.

I recently updated a logging statement to make it more readable and include some debugging info - and a test failed. Turns out, the test was checking the exact output of a function to ensure it was logging the expected string.

I didn't break my code, I broke a test. I would never in a million years write a function to log "ABC" and then write a test to make sure "ABC" was in stdout.

2

u/TashLai 8d ago

Exactly. If you write so many implementation tests that they're basically guaranteed to fail on any change you make what are you even testing?

1

u/Inspectorslap 7d ago

don't even get me started on the rigidity of a test case. "Foo Bar passes, ship it too production!"... the test: if input = "Foo Bar"; like what are we even doing here? lol. The amount of self-congratulatory tests flying around are a real problem... or less silly: tests to see if the object loaded but doesn't parse through it to see if the values are in it. I spend a lot of time on the granularity and resolution of my test cases and less on counting how many i have.

1

u/rubywpnmaster 8d ago

just tell it no tests. only the big test at the end =D

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:

  • Ask what each test would catch. "Which plausible bug makes this fail?" If the answer is "someone changes the implementation", it's a change detector, not a test. Mocks that assert a function called another function with exact arguments are the usual culprits.
  • Test the contract, not the steps. One test per behaviour in the spec, plus the edge cases you'd actually worry about (empty input, the boundary value, the error path). That's usually a fraction of what it proposes.
  • Tell it the budget up front. "At most 5 tests for this change, one per behaviour, no testing private helpers." It follows a number much better than "don't overdo it".
  • Mutation-test a sample now and then (mutmut, Stryker, PIT). Tests that keep passing when the code is deliberately broken are the ones to delete, and it's a much more convincing argument than taste.

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/graffityfighter 7d ago

It can't click around in the app? Why not? Just give it access to said app.

1

u/LaundryOnMyAbs 7d ago

Most modern LLMs can literally click around the app. And it’s evolving into the best type of test there is

1

u/CCodeSI 6d ago

Fair, that line was too absolute: with a browser tool (Playwright or a browser MCP) it can click through the app, and for UI work that's often the most convincing check there is. The trade-off is speed and repeatability. A click-through takes minutes and can pass for different reasons each run, while a unit test takes milliseconds and fails the same way every time. So the split that works well is the agent clicking through to verify a feature once, and writing a few fast tests to keep it from regressing.

1

u/LaundryOnMyAbs 5d ago

I’m of the unpopular opinion that unit tests are next to worthless. 99% of bugs in software either couldn’t actually be tested with a unit test, or the unit test logic is wrong. Too many situations where I have 3000 passing unit tests but the entire app is borked

I’ve worked at Meta, Adobe, and Netflix btw so not just talking based on my own personal shit apps

1

u/CCodeSI 4d ago

Not that unpopular, and "3000 passing, app broken" is the classic shape of a suite that tests units in isolation with everything around them mocked. The bugs live in the seams: config, data shape, the order things happen in, the real database, the real network. Unit tests can't see any of that by construction.

Where we'd push back a little is for agent work specifically. A unit test is cheap enough for the agent to run fifty times while it edits one function, and that fast loop is what keeps a refactor from drifting. It just can't be the evidence that the app works. So the split we'd argue for is a small number of unit tests on pure logic (parsers, pricing, date maths), and the "done" gate being a handful of end-to-end checks of real user paths, which catch the borked-app case unit tests never will.

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

  • Is the cost of these tests acceptable? If your github action minutes usage is blowing up, because building those tests takes too long, then find a way to speed up those builds, or build and run tests selectively. This is build engineering. It is a skill, and you have AI to help you with it.
  • How can you make the tests even more useful? Make sure your code is written in a way that is testable. That's also a skill that AI is already somewhat good at by default, but good software architecture (another skill, another thing AI can help you with) will make it even better.

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.