Let AI Write Your Code, But Not Your Tests
AI-generated code has become a fundamental part of programming, with tools assisting in everything from autocompletion to full implementations. However, the biggest challenge is trust.
Hello, developers! 🚀
Welcome back to the Learn Agile Practices newsletter, your weekly dose of insights to power up your software development journey through Agile Technical Practices and Methodologies!
Before starting, I quickly remind you that my brand new Test-Driven Development 101 5-day Email Course is available: it is the introduction to TDD I wish I had when I started learning it, so I think you will find it very useful!
As a subscriber to my newsletter, you can have it with a 10EUR discount! 👇
Now, let's dive into today's micro-topic!
In short
🤖 AI-generated code has become a fundamental part of programming, with tools assisting in everything from autocompletion to full implementations. However, the biggest challenge is trust.
🧪 AI can generate code, but it struggles to define intent. In TDD, tests establish the desired behavior before implementation, ensuring correctness.
🔧 Refactoring ensures maintainability and scalability, but AI lacks human intuition for trade-offs like readability and long-term design. While AI can assist with optimizations, developers remain responsible for keeping code adaptable.
🚀 As AI advances, coding may shift from manual implementation to defining requirements and testing. This could elevate the role of QA professionals while reinforcing developers as problem-solvers.
Coding with AI is the “new normal”
AI-generated code is here, and it has already changed how we work as programmers. We all use an AI autocompletion help today, and some of us even much more help from AI.
The current main problem with AI-generated code is trust: sometimes it’s good enough, sometimes it’s completely wrong. It still requires a lot of additional work to check the quality of the code generated. Someone could say that we need a tool that help us in evaluating this resulting code… but hey, we already have it!
It’s TDD - Test-Driven Development.
In the latest months, I have explored this AI-for-coding trend among TDD developers and practitioners, and most of them share a common sentiment:
“I’m happy to let AI generate code for the GREEN step, but I want to do the RED myself.”
Let’s reflect about that.
AI Can Write Code, But It Can’t Define Intent
Code is just a tool—a means to an end. We write it not because we want to, but because we have to. If AI can generate reliable implementations, that would be great!
But before implementation, we first need to define what the software should do. In TDD, we formalize this through code with tests written before even implementing the code: the test will fail at first, since code doesn’t exists yet, then it will succeed once the objective has been reached.
Here’s why AI cannot (yet? not sure) replace human judgment in these steps:
✅ Tests define intent. They specify the expected behavior of a system. If AI writes them, who verifies that the expectations are correct?
✅ Code is temporary, but understanding is permanent. If AI writes an entire codebase, will developers still understand it? Writing tests forces us to engage deeply with our problem domain.
What about refactoring?
The strategy I described covers the RED and the GREEN step of the TDD cycle. But there is one more missing: the REFACTORING step.
The main reason for this step being part of the cycle is that we need to ensure our code remains maintainable and scalable - moreover, we need to ensure our code remains easy to change over time. So, how can AI help us with refactoring?
Refactoring requires context. AI can suggest optimizations, but it lacks human intuition for trade-offs like readability, scalability, and long-term maintainability. In the end, even if it’s AI-generated, developers will be the responsible for maintaining it.
Potentially, at some point, AI might be power enough to handle an entire codebase by itself - but until then, it’s better if we own our refactoring, even if with the help of AI.
AI as a Coding Partner, Not a Replacement
Maybe one day, AI will maintain entire projects. If that happens, the most valuable skill won’t be writing code—it will be writing tests and defining requirements. The shift might even open new opportunities, where QA professionals become developers by writing test cases and prompts instead of traditional code.
Developers will still hold a privileged position, though. At the end of the day, we are problem-solvers, not just coders. And as AI takes over more of the mechanical tasks, our focus will shift toward higher-level thinking, testing, and business logic.
So go ahead—let AI write code, but own your tests.
Until next time, happy coding! 🤓👩💻👨💻
🇮🇹 Calling my Italian readers!
🚀 Want to master Continuous Integration and safely hide work in progress?
Join my hands-on Mastering CI: Fast Releases for Modern Team Workshop, organized in collaboration with Crafted Software Community, where you'll learn to implement these techniques in real-world projects. Say goodbye to long-lived branches and risky deployments—embrace seamless integration with confidence!
📅 Dates: March 29th, April 5th and April 12th. (3h sessions, 10am-1pm).
🎟️ Spots are limited—Sign up now and take your development workflow to the next level! 🚀
Until next time, happy coding! 🤓👩💻👨💻