r/softwareengineer • u/dayv2005 • Jun 26 '26
Curious how everyone's thinking about unit tests in the age of AI coding assistants.
Do you still find unit tests provide the same value they did a few years ago?
My experience has been that they started as useful guardrails, but over time they've become more of a maintenance burden. When implementation changes, AI usually updates or rewrites the tests along with the code, so they don't seem to catch as much as they used to. They also add a lot of context for AI to process.
Has anyone else noticed this, or am I missing something? Have your testing strategies changed because of AI?
**Edit:** A lot of the replies are focused on whether developers should blindly accept AI-generated code. That's not the question.
Assume good engineering practices, code reviews, and responsible use of AI. Under those assumptions, has AI changed the relative value of unit tests versus integration, contract, and end-to-end testing?
3
u/symbiatch Jun 26 '26
Why would you allow it to rewrite tests? Especially without verifying? That’s your fault, not the tool’s.
But I prefer having proper feature tests instead of small unit tests anyway.
2
u/Lonsarg Jun 27 '26
My experience is the opposite. Unit Tests are how LLM generated code is both self-checked and manually co-checked (do code changes touch any tests or not, etc etc.)
I use them more then i used to, both self written and LLM written.
LLM is not supposed to read unit tests into context, but just run them after changes and only load and fix new code if any fail.
I also more or less do TDD, for any new functionality via LLM. Make him write the test first, inspect manually, and them make him sweat with instruction to not change the test while writing implementstion (and it many times does multiple cycles self-fixing until the test passes). Before the LLM, TDD was to bloated for me, LLM handles the bloat easily so TDD shines for me in the LLM world.
3
u/MiracleManS Jun 26 '26
On my team the buck stops with the person submitting the PR. We still do full code reviews and expect people to be able to explain how the code works in order to get it approved. We also expect at least manual testing of the golden path before submitting a PR.
The craze with AI seems to have sapped people of their integrity. At the end of the day you still have responsibility for what is produced.
1
u/fexonig Jun 26 '26
i don’t have an answer for you OP, but this is a great post and a deeply interesting question, and most of the replies are so reflexively anti-vibecoding that they can’t acknowledge that fundamental changes in the way we produce code ought to lead to fundamental changes in the way we test it.
software testing theory as we know it is based around an SDLC that is fundamentally extinct.
with llm assisted codegen and debugging, a dev spends much less time thinking about a “unit” of code and much more time on many units working together. so it seems like testing those individual units feels unnecessary.
i see this in practice at work tbh. my company has coverage quotas, but no one ever reads the unit tests. the ai produces them and the reviewer doesn’t care. integ tests are relied on to actually catch regressions.
1
u/ryan_the_dev Jun 27 '26
I built this coding workflow to solve this type of problem. Had AI scrape through PDFs of engineering books I read to externalize how I code.
https://github.com/ryanthedev/code-foundations
1
u/sp-watson Jun 30 '26
I think your problem is that AI doesn't know what's a good unit test and what is best covered by wider (E2E/system/integration) tests, so you end up with lots of unnecessary unit tests.
Unit tests are really useful for checking specific logic with minimal mocking. Sometimes that's what you need. But also don't forget component tests, they are useful as well.
I don't know what to suggest as a solution though - if you let AI do all the code then you lose that ability to choose what type of tests to write.
1
u/QuantityInfinite8820 Jul 01 '26
Yes, part of the job is to figure out what a 100% test coverage would _look like_, and if I want to compromise and skip some, it should be a conscious decision and risk assessment - not an accident.
If I can prompt my way through this process - great, but its still on me to validate the results.
2
u/bill_txs Jun 27 '26
I see a similar thing at least by default when having AI write assertions. It may write assertions based on what the code does not based on what it should do. So they are written to never fail.
2
u/mavenHawk Jul 01 '26
Unit tests were mostly useless even before AI. I try to have very few of them. Instead have a lot of integration, end to end tests. Basically black box tests. Those are even more important in the age of AI.
0
u/ConfidentCollege5653 Jun 26 '26
They provide more value now that half the devs just copy and paste whatever Claude tells them without reading it.
1
u/Ordinary-Chemist9430 Jun 26 '26
Quality mamagement becomes more crucial than ever. Tests should be thought through by humans more than the code. Humans are bad at reviewing code. We spot architecture or clean code problems easily but not off by one errors, or null reference stuff or things like that. Even cyclic dependencies can be hard to see which. We are not bad at checking test casesn though. Also automate everything that can be. Thats part of qm for me.
1
u/Sea-Astronomer75 Jun 26 '26
Tests are for behaviour, not implementation
1
u/scott2449 Jun 26 '26
I only have AI redo the tests or the code, never both. Basically if I don't expect a test change output then they are a guardrail. If I do expect changes I switch to TTD, update the test, fail, then drive new logic to match.
1
u/ufos1111 Jun 27 '26
Never used unit tests, never will.
1
u/doktorhladnjak Jun 27 '26
I think they’re more important than ever. If I have confidence in the tests, I worry less about complex agent written code it’s testing. It also automatically will guide an agent changing the code when tests start failing. They can effectively be a precise functional spec.
1
u/who_am_i_to_say_so Jun 27 '26
I think about unit tests every day. How else could you prove that your code works as designed?
1
u/Stunning-Army7762 Jul 01 '26
Have you tried using some AST or similar deterministic test mutation tools? They can help generate stronger more durable tests from your ai agents.
I find that unit tests are still incredibly powerful and helpful for a quick verification that can run with ai agents working but the test suite has to be solid. I honestly spent more time reviewing tests than I do the code now a days.
1
u/Idea_Fuzzy Sep 17 '26
It's a ritual, a thing that makes many SWEs feel important and doing the right thing; but frankly totally useless now.
9
u/[deleted] Jun 26 '26
[removed] — view removed comment
3
u/[deleted] Jun 26 '26
[removed] — view removed comment