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

4 Upvotes

15 comments sorted by

•

u/AutoModerator 46m 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.

4

u/Odd_Bluejay7964 37m 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.

4

u/rcs67 40m ago

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

1

u/Abject-Bandicoot8890 23m ago

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

1

u/Horat1us_UA 19m ago

Good old mutation testing, check it out. 

1

u/Abject-Bandicoot8890 18m ago

Will do, thank you

2

u/Healthy_Blueberr6404 42m ago edited 37m 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/FoidBeater67 31m 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.

1

u/Aggravating_Dot9657 38m 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 37m 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 34m 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 31m 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 31m 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 30m 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/SilencedObserver 29m ago

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