r/learnjavascript • u/Human-Philosopher782 • Apr 18 '26
Do you trust AI-generated tests, or do they cause more problems than they solve?
Genuine question. I've tried a few AI test generation tools and the pattern is always the same: it generates a full spec file, I spend time tweaking mocks and edge cases, then on the next run it regenerates everything and my changes are gone.
It made me think — the problem isn't AI writing bad tests. The problem is AI writing tests into files that humans also edit, with no concept of ownership.
Has anyone found a tool or workflow that handles this well? Or is the whole approach of AI-generated tests fundamentally at odds with how developers actually work?
4
u/briznady Apr 19 '26 edited Apr 19 '26
AI generated tests might manage to generate tests that cover what the code currently does. What it definitely won’t do is generate tests that cover what the code is supposed to do.
2
u/tb5841 Apr 18 '26
After you've gone through, tweaked and edited etc, stage all your changes. Then when it regenerates everything, its latest change will be unstaged and you can compare - ir discard it if you don't like it.
Assuming you're using git, of course.
5
u/dymos helpful Apr 18 '26
Yeah, don't do that. :P
If the AI is regenerating the whole test that's a big nope for me. There's something wrong with the prices or the prompt.
I haven't personally seen it do this, so perhaps you can expand on when this happens? Because in my experience the coding agent has just updated test files rather than rewrite my changes.
1
u/lalaboy69 Apr 19 '26
You can have AI help you write tests, but they should be documented in their own folder and you should use your stack's testing tools to execute them as well as determine coverage. Learn the Gherkin framework as a base.
1
u/daronello Apr 19 '26
the real issue isn't ownership, it's that most tools treat test gen as a one-shot dump. something like Saff Squeeze or mutation testing (stryker) forces you to think about what tests actualy prove. Zencoder's unit testing agent handles the framework-specific stuff without clobbering your edits, but pairing any generator with mutation testing catches the gaps.
1
u/TheRNGuy May 01 '26
Trust if they're made correctly.
You can read generated code.
1
u/Alive-Cake-3045 May 04 '26
Burned by this exact thing on a client project, AI kept overwriting hand-tuned mocks every single run.
Treat the generated file as a first draft, commit it, and never let AI touch it again. Use it to suggest new tests but write them in yourself. Happy path coverage, AI is fine. Edge cases still need a human who actually understands what failure looks like.
1
u/Interesting_Deer97 Oct 26 '26
manual testing for every tiny change is just not gonna scale. last week i started using testavi to keep my flows from breaking when the ui shifts, which really helped me stop chasing brittle scripts around all day.
0
u/hyrumwhite Apr 18 '26
There should be no difference. If you’re using ai to generate tests, they should represent the tests that you would have written by hand, and be in the style that you would have written as well.
The same goes for normal code.