My biggest beef with AI-generated code

It's the tests.

Automated tests have always been one of the biggest leverage points in software development. They were important before LLMs, to the point you could not expect to get hired in any good engineering team without being able to demonstrate mastery of TDD during an interview.

And they absolutely critical now, in the sense that AI coding agents cannot do anything without them. Their ability to make code that works is completely dependent on the application's existing test suite, and their ability to generate good new tests to validate the implementation, and keep them from exiting the agentic loop before the program is actually working.

This past week, I've been developing a rich new feature for an ecommerce fulfillment system. Pretty mission-critical, as you might imagine. So I was using one of the most expensive, recent, and supposedly advanced frontier models available to the public right now.

And even with this cutting edge LLM...

The test suite it created was filled with issues:

The tricky part is that none of these are a problem at first.

Because the tests pass, and everything seems to work great. They only become a problem later, when you need to substantially upgrade what the codebase is doing.

At which point you realize your test suite carries a great deal of technical debt, where you (or the coding agent) must substantially revise a huge chunk in order to move forward. In ways that, in my own experience, human-written test suites would never need to change.

So what's the solution?

  1. Make sure some well-written tests exist, and point them out to the coding agent as an example of how to do it.

  2. Audit at least some of the tests which are generated. If they are "off" in any way, add rules - e.g. to your AGENTS.md, or a custom agent skill - to direct the coding agent to do better.

  3. A tip I have found useful recently: show the coding agent a badly-written unit test it wrote, and also a similar well-written test (that either you or it wrote). Prompt it to give you some agent rules you can feed it to get the kind of test code you want next time. You can even use these to improve the current tests, while you're at it.

That's how I am dealing with the situation.

This all assumes you know how to:

  1. Write good unit tests
  2. Work with coding agents
  3. Write English well enough to direct the AI successfully

All of which you learn in Boosted Code.

If you are in BC already, think about which of these three you most need to focus on next, and make a plan for when to start on that part of the curriculum. Ask in the community if you need help choosing where to start.

And if you are not in Boosted Code yet, learn more about it here:

About Boosted Code