r/ClaudeCode • • 6h ago

Help/Question Unit Tests no longer source of truth. Searching for suggestions.

​

In the current state of AI, how can a team ensure backwards compatibility and keeping existing function. Context, backend java engineer on a team with a revolving door of engineers. Now people can push features with large code changes and fix the unit tests, so one cannot solely rely on unit tests to ensure existing functionality is not broken with new code changes. Any suggestions to leverage Claude? This could more be a way of working or better prompting for Claude code reviews.

3 Upvotes

31 comments sorted by

•

u/AutoModerator 6h 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.

2

u/Asalakabim 4h ago

ask claude about "team with a revolving door of engineers", i would recommend the prompt "how can we stop being a piece of shit company?"

1

u/L8erG8er8 3h ago

Sorry we have contactors. But I agree

6

u/Odd_Bluejay7964 6h ago

People could always push large changes and fix unit tests to get them to pass, that's not new. Processes, expectations, and accountability were and still are what drive the outcome. The root cause of your issue is not AI, that is only driving the scale of it.

1

u/codewithcoffeeonly 5h ago

it is what it is. nobody wants to test, it's way easier to just wait for the fire to appear and then act like it was not preventable. at least for the critical stuff we use a mcp for quick human testing, because nobody wants to create tests either. Guess we are part of the problem...

6

u/rcs67 6h ago

Mutate your code and see if your tests catch it. There are already tools for this.

1

u/Abject-Bandicoot8890 5h ago

This sounds interesting, I’m genuinely curious, can you expand more on this?

1

u/Horat1us_UA 5h ago

Good old mutation testing, check it out. 

1

u/Abject-Bandicoot8890 5h ago

Will do, thank you

1

u/UnstableManifolds 3h ago

Mutation testing works only when unit tests are actually developed to check business logic "as humans would", if it makes sense; if unit tests are implemented for the sake of technically testing the code (something that LLMs love to do), it will not improve test quality imho.

3

u/FoidBeater67 5h ago

Add mutation testing to increase quality of your unit tests. AI tests are ass and that's why you can't rely on your tests. Also add end product tests. AI can run them using computer control.

2

u/Healthy_Blueberr6404 6h ago edited 6h ago

maintain an index/map/changelog and have all users' harness go through a gate/audit that checks it first to ensure no code is redundant/breaking or reinventing wheels, and then design a universal test harness so testing/measuring/logging/ledgers are centralized. (append only is good idea- human-in-the-loop audited once a week)

most of complexity is solved simply by maintaining one source of truth and gating it for everyone for consistency, and then using per-project or per-lang overrides that change flexibility slightly on specialized cases. unit tests are just this testing harness applied on-demand to engineer tests that are aware of big and small context.

ie instead of "lets test Y!" confidently, it'll say "lets test Y, but first i see X Z and W have similar behavior. let me see how it runs against those, or if there's redundancy we can remove"

costs go up in the short term. long term costs decrease as errors/deviations exist in less frequency.

2

u/SilencedObserver 5h ago

Anyone not running post-deployment integration tests is going to wake up to a hard problem at scale.

0

u/UnstableManifolds 3h ago

Source code and unit testing is black-box nowadays, deterministic integration testing (even in local environment) is the only way to actually define a spec implementation Done, when successful

1

u/SilencedObserver 3h ago

You’ve just described one approach to software delivery.

Referring to it as a black box describes your skill set.

1

u/UnstableManifolds 2h ago

Care to expand? What I'm saying is that with the current required pace no one is actually checking the PRs and, generally, inspecting code, so we're moving from a design - build - verify where human involvement is required in all steps, to a model where human is basically present in the design phase and in the verification phase (hardening the integration testing process)

1

u/SilencedObserver 2h ago

What I'm saying is that with the current required pace no one is actually checking the PRs

So you're caught in the hype machine, and not actually shipping software. Got it.

My position, personally, is that companies believing the Anthropic hype cycle of "stop reading and writing code" are going to find themselves on the responsible disclosure list for data leaks.

People shipping code need to own what they ship. Whether you believe that or not is up to you, but based on this interaction alone, you'd fail an interview where I work, and we're an AI-first dev shop.

1

u/UnstableManifolds 12m ago

I get where you're coming from, but I think there are various way of owning stuff. I test the behaviour of the code via thorough integration testing (which involves end to end testing) and user testing, it doesn't rule out security problems but of course the process involves scanning the code with static analysis tools, pen testing, and so on. Basically we realized that in order to remove the bottleneck (the human reviewing stuff) we needed to strengthen the perimeter around it, so being smarter in the design (since you cannot fix it at build time anymore) and in the testing allows to ship functionalities better.

1

u/Aggravating_Dot9657 6h ago

The only thing I can think of for these large, AI-driven PRs is a separate task as part of a build or deployment pipeline that evaluates the changes to unit tests separately and determines if any changes change assumptions about existing functionality. But that would also most likely be an AI task. Welcome to the age of AI!

1

u/who_you_are 6h ago

it won't cover everything but lambda users know and often use Excel file to provide data. So one thing you can always do is allow to have CSV as true table for values vs expected value using integration-like tests.

Those files are less likely to change since it is the tests framework that should be the one adapting. Yes your columns header and values may change overtime, but they are less likely than a unit tests.

You could also always create some Claude skill to review changes once in a while to try to help you listings expected structure changes and to cross match the CSV changes. It won't change a human review I but it may be able to flag errors

1

u/leo_heo 5h ago

id make editing an existing test need a written reason. the task spec says which behavior is allowed to change, and any test edit outside that goes back before review

1

u/Wh00ster 5h ago

Fundamentally your prompt is the source of truth. You asked it to do something. And it did whatever it thinks you wanted.

1

u/flypod-dev 5h ago

put the tests that pin what callers depend on in their own folder and make CODEOWNERS on it a required review, so an edit there needs a named person's ok no matter how big the rest of the PR is.

in my project the outside contract (cli flags, error codes, exit codes) is also checked against the docs by a test, so changing that behaviour fails unless the README changes in the same diff, and a docs diff is much harder to skim past than a tweaked assertion. the agent can still rewrite unit tests freely, it just can't quietly change what callers rely on.

1

u/aaronsuns 5h ago

One angle not covered yet: have CI fail when a PR removes or modifies lines in existing test files, and allow only added tests. A simple diff check on the test directories makes it obvious when someone has edited an old assertion to match new behavior. Pair that with characterization tests that capture the current outputs of key services or endpoints on the main branch, since those baselines are much harder to regenerate quietly than individual unit assertions.

1

u/UnstableManifolds 3h ago

LLMs LOVE to create tests, so much that sometimes you need to run "Occam's Razor" session instructing it to remove unnecessary tests, so that would not work at least in my experience

1

u/ChemicalExcellent463 4h ago

i don't let the agent writing the feature write or edit the tests, that goes through a separate run. review comes from a different vendor's model in a different harness, fresh session that never saw the coding chat.

1

u/CandidSystem6155 4h ago

What worked for us was not banning test edits but making the weakening visible. Before a change is accepted, a check diffs the test files and counts assertions before and after. If the count drops, or a new @Disabled/skip shows up, it stops and a person has to sign off. New tests pass freely.

We first had this as an editor hook and found it never saw edits made with sed from the shell, so the diff check in the pipeline is the one we actually trust, no matter which tool made the change.

1

u/Patient-Cattle-2397 3h ago

Keep a few requests from the previous client version and run them against the new backend in CI. Include an older request with a field missing that newer clients always send. If a PR needs to change one of those expected responses, make the reviewer approve that contract change explicitly.

1

u/False_Bear_8645 2h ago

Preferable if the code is designed for TDD from the beginning it's much easier. The general pratice is that new code use TDD and refactor older code it touch along the way.

1

u/SirRobinBlibs 2h ago

The existing unit tests can't be the safety net if they get rewritten in the same PR as the change. A separate layer that nobody edits casually works better: characterization tests that record what the system does today at the API or service boundary (real requests in, responses snapshotted), in their own folder with a CODEOWNERS entry and required code-owner review. Then a PR that "fixes" a behaviour change has to touch that folder, and that's visible in review instead of buried in 40 updated assertions.

For Claude specifically: put a deny rule like Edit(src/test/characterization/**) in the committed .claude/settings.json so it can't quietly update them, and in reviews ask it to list every changed assertion with the old and new value. Mutation testing, like others said, then tells you whether the remaining tests would even notice a change.

1

u/jleechanworldai 13m ago

What helped was treating edits to existing tests as their own review item. "Tests pass" isn't enough, because a reviewer can't tell if the tests got bent to fit the code. If an assertion gets loosened, I count that as a behavior change and it gets the full review. Small diff or not.

New behavior starts with a failing test, so the test exists before the code does. And approvals are tied to a specific commit: CI green on the current head, and if the head moves I check what the new diff could break before I reuse an earlier approval.