Is anyone here successfully using Generative AI (ChatGPT, Gemini) to write unit tests for legacy code? We have a massive codebase with very little coverage, and I’m wondering if these AI tools can help us catch up without spending months of manual labor.
3 answers
We’ve been using Generative AI (ChatGPT, Gemini) to generate boilerplate tests for our Python microservices. It’s incredibly efficient at creating mock data and testing basic edge cases. The real challenge is when the legacy code is tightly coupled; the AI often suggests tests that are hard to implement without significant refactoring. I recommend using it to generate the "happy path" tests first and then manually writing the more complex integration tests to ensure system stability.
Have you noticed a decrease in the time spent on debugging after implementing these AI-generated tests? I'm worried about the "technical debt" of maintaining tests we didn't write.
It's great for explaining what a complex function does before you even start writing the tests. It saves a lot of "reverse engineering" time.
That's a great point, Sandra. I often use Generative AI (ChatGPT, Gemini) to document the logic first, then I ask it to generate the tests based on that documentation.
Larry, the debugging time has dropped, but the maintenance is a real concern. If the code changes, the Generative AI (ChatGPT, Gemini) tests might break in ways that aren't immediately obvious. We treat AI-generated tests as "drafts" that must be peer-reviewed before being merged into the main branch.