The TDD (test-driven growth) workflow can be utilized with AI-augmented coding in a number of methods:
- Human writes the exams: A human defines the take a look at eventualities in some type, be it in pure language, in BDD model, or instantly in code. Then AI writes the implementation to make these exams move (with possibly a primary step that transforms the human’s eventualities into code).
- Evaluation checkpoint for the human: AI writes a failing take a look at, human appears to be like at it to evaluate that the take a look at is testing the needed habits, then AI writes the implementation
- Absolutely contained in the agentic loop: Immediate an agent to write down failing exams first, one after the other, after which write the implementation and verify that the beforehand failing take a look at is inexperienced.
At this stage, that final utilization is by far the most typical one. However does it actually make a distinction, asking an agent to comply with a TDD workflow totally inside its personal loop? Does it actually present worth, or is it one of many uncommon examples the place what’s good for the human may be irrelevant or dangerous for a coding agent?
I created an exploratory analysis setup to scratch the floor of this query and see what I’d discover. It’s removed from a complete and structured eval outcome, nevertheless it did create some hypotheses to consider if you’re working arduous to get your agent to make use of TDD.
TLDR; Primarily based on Opus’s judgment of the standard of the outcomes, there was no clearly discernable distinction based mostly on TDD workflow versus no TDD workflow. Quite the opposite, greater than as soon as Opus ranked the non-TDD workflow options barely greater in design and take a look at high quality. There was additionally no significant distinction in mutation scores throughout the options.
The setup
- Duties: I created a small, medium and a bigger process with the assistance of Claude, all inexperienced subject implementations of a little bit of enterprise logic. I had it make a bunch of strategies, asking for idiosyncratic and particular logic to extend the likelihood that there will likely be variance between options, and never only a repetition of one thing that’s already dominant within the coaching knowledge.
- Directions: In all runs, I included directions to realize at the least 80% code protection.
- Mannequin: I used Sonnet 4.6 to generate the options.
- Judgment of TDD adherence: Analysis of adherence to TDD was additionally carried out by Sonnet 4.6.
- Judgment of options: Opus 4.8 in contrast the standard of each options and their exams, with out data of how the options have been created. I did not give very particular inputs on what I think about to be good high quality, as this was a really open exploration. And in my expertise, the extra particular I’d have gotten, the extra the mannequin may have over-indexed unnecessarily on the standard standards I record. Opus has proven to be fairly a succesful mannequin by way of judgment of code high quality. For its rating of the options, it created a rubric on the fly to move to all subagents that have been evaluating the person options.
While you draw your personal conclusions from my outcomes, the primary caveats to think about are:
- That is clearly a really small pattern dimension, so take it with a grain of salt
- Judgment of what “high quality” means was nearly totally left to Opus (with just a few pointers about take a look at high quality)
- Not one of the runs ever adopted TDD completely, however fairly effectively
- The coding duties given to the brokers have been all greenfield and comparatively small, purely about enterprise logic
How good are brokers even at TDD?
Earlier than I even began, I wanted to ensure the TDD directions have been really adopted. Traditionally that hasn’t gone effectively for me: brokers typically write the implementation first and generate exams after, skip confirming the crimson step, or over-implement forward of the present take a look at so the following one passes with out ever going crimson.
The immediate I ended up utilizing labored effectively sufficient with Sonnet to make use of for the comparability, although all classes confirmed a few of these failures to an extent. For every TDD run, I had an impartial agent decide how effectively the workflow was adopted, based mostly on the session transcript, in order that I would not by accident have in mind a run that did not meaningfully do it.
Outcomes
I created 5 batches of options, with two non-TDD and two TDD options every. In a single batch, I additionally added two runs that have been instructed to write down the exams first, with out full TDD self-discipline (no incremental crimson/inexperienced).
Throughout the small (1 batch) and medium (3 batches) duties there was a little bit of a sample: Opus ranked the 2 non-TDD options #1 and #2, and the 2 TDD options #3 and #4. Solely as soon as – after I strengthened the TDD immediate with a extra specific refactor-and-design-review step – did a TDD answer rank #1. In that very same batch, the opposite TDD answer, run with the equivalent immediate, ranked final although… For the bigger process, TDD landed within the center, whereas the 2 non-TDD runs took each the most effective and the worst spot.
(Particulars within the appendix)
Hypotheses
So in abstract, each TDD and non-TDD scored each as a greatest and a worst answer throughout the batches, with TDD general performing barely worse.
Requested to have a look at the session traces to hypothesize concerning the outcomes with data of which workflow was used for which, Opus discovered that the non-TDD and test-first runs at all times created the total design (structure, knowledge varieties, edge circumstances, contracts) earlier than writing any code or exams, fairly than working by it one requirement/take a look at at a time. That gave the impression to be the factor that moved the needle barely in the direction of comparatively higher knowledge fashions, extra cross-cutting edge circumstances, and higher completeness of the performance.
The TDD directions actively work in opposition to such an up entrance design step. The design in these runs emerged from the sum of many locally-minimal selections and was not often revisited, so it tended to land on no matter form the primary take a look at occurred to lock in. Behaviour the agent did not assume to write down a take a look at for did not get carried out in any respect.
After I chatted to Ivett Ördög about this, she had this idea: “The way in which AI brokers have been skilled is that they’ve seen accomplished features and descriptions of these features. The variety of precise step-by-step TDD examples they’ve seen is a tiny a part of the coaching knowledge. That signifies that the LLM has an inside illustration of code that may be a direct translation of necessities to code, and never a means of how one can get to that illustration.”
Targets of TDD – nonetheless achieved within the agent loop?
The next are my basic reflections about utilizing TDD within the agent loop, not solely based mostly on this experiment. I am going by the last word targets I personally have after I use TDD, skipping a number of the ones which are about having exams within the first place, and unit exams specifically (like refactoring security internet, residing documentation, take a look at protection), focussing on those which are particular to the TDD workflow.
Check first >> Avoiding tautology
Check-first makes it simpler to say the output I need, fairly than restating the implementation. Such a take a look at can by no means fail when the implementation is incorrect because it was derived from the identical logic it is supposedly checking. When the assertions are decoupled from the particular implementation path, the take a look at can really catch when the behaviour just isn’t what I meant.
Nonetheless achieved within the agent loop?
In my experiment, some TDD classes had this drawback anyway, despite writing the take a look at first. In a single significantly apparent instance, exams checked the implementation’s output in opposition to itself, re-running the identical code to supply the “anticipated” reply (see 4. on this record of observations). Writing the take a look at first would not reliably forestall this – it’d make it much less possible, which is all we are able to ever hope for anyway with LLMs, however from this small knowledge set I can not draw any conclusions about that likelihood.
Check first >> Testability
Check-first ensures the code is designed to be testable from the beginning, fairly than retrofitting exams which are extra complicated and brittle than needed.
Nonetheless achieved within the agent loop?
The outcomes did not give me any clear lower alerts both method. For what it is value, the dimensions and nature of the duties I selected did not require a number of design complexity that would have surfaced this. To an extent although, testability is a corollary to driving design (see under).
Pink-green >> Check effectiveness
Observing a take a look at fail first, then succeed (red-green), proves it should really catch a regression.
Nonetheless achieved within the agent loop?
How a lot sense does this actually make when the human is eliminated? Watching a take a look at go crimson is barely proof of something if somebody is checking why it went crimson. When the agent each writes the take a look at and confirms it failed, a crimson take a look at tells you the agent ran it and noticed failure, not that the failure was for the proper cause. The evaluations of TDD adherence in my experiment additionally present this: brokers nonetheless typically skipped or faked the crimson step, or carried out forward of the take a look at in order that it handed instantly. Regression effectiveness could be monitored and improved with mutation testing (as I wrote about right here). Mutation scores throughout the options did not present any alerts that TDD runs produced meaningfully higher mutation scores than non-TDD runs. I do not actually care how regression high quality was achieved, so long as I’ve a mechanism to see how good it’s.
Check first, red-green-refactor >> Driving higher design
Writing the take a look at first forces us to specify utilization earlier than implementation, pushing towards higher interfaces and extra modular code. The refactoring step within the TDD loop additional pushes us to enhance the design step-by-step.
Nonetheless achieved within the agent loop?
The experiment at the least hasn’t demonstrated superior design within the TDD runs in any respect. I now even marvel if TDD makes it worse, based mostly on Opus’s scoring, because the non-TDD options as a rule have been ranked greater, and the design flaws it listed made sense to me. However the knowledge set is after all too small to definitively conclude something. (If anyone has time and tokens to run a bigger experiment, that may be very fascinating!)
When people write a take a look at first, it forces us to consider utilization earlier than implementation, we now have to sit down with the friction of specifying behaviour and expectations earlier than realizing how one can construct it. An agent would not expertise that and may write a take a look at the identical instantaneous it plans an implementation. With no human checkpoint between the 2, is there actually any objective left to writing the take a look at first?
Small steps >> YAGNI
Writing solely sufficient code to move the following take a look at is about restraint. It is imagined to cease us from constructing abstractions or dealing with circumstances no one has requested for but.
Nonetheless achieved within the agent loop?
It is a very human-centered profit that will get misplaced when an agent does TDD by itself. We do not get to sit down in that friction anymore the place we actually have to consider all of the intricacies of what we’re constructing. That’s theoretically shifting to once we are writing the specs to offer to an agent, however we do not have a TDD-like mechanism there that lets us assume the spec by in small steps.
Could not an agent work in these small steps although and ask us questions at any time when it finds one thing that may be pointless? In my basic expertise, they are not excellent at that. And within the experiment as effectively, minimal-implementation directions did not reliably cease them from constructing extra. They steadily overshot and carried out greater than the present take a look at demanded, as a result of that they had the total requirement obtainable. We often do not spoon-feed the spec one after the other, that may be very inefficient.
Small steps >> Quick, localized suggestions
Taking one small step at a time signifies that when a take a look at fails, I do know nearly precisely what prompted it, as the one factor that modified for the reason that final inexperienced state is the one factor you simply wrote.
Nonetheless achieved within the agent loop?
The setup did not present if brokers obtained caught debugging extra steadily with versus with out TDD. However in my basic expertise, brokers are often moderately good at determining why a take a look at is crimson, even with out having taken small, deliberate steps to get there. I am nonetheless uncertain if the instances once they do get caught might be meaningfully mitigated with small TDD steps, and if the general price/profit comparability would maintain up.
Small steps >> Confidence and studying
In Kent Beck’s preface to “Check-driven Growth by instance”, his greatest rationale for TDD is “managing worry”. He says that the legit worry of arduous issues makes builders tentative, much less communicative, and avoidant of suggestions. With TDD, every passing take a look at reveals us progress, so we are able to calm down realizing that progress is locked in. The exams are a psychological mechanism that helps us hold going.
Nonetheless achieved within the agent loop?
That is very a lot about managing a human’s worry and giving a human permission to calm down. That does not switch when the agent is doing TDD within the loop, because it would not give me the identical management and belief as after I do it myself, step-by-step.
Prices
No less than 3x the tokens
See detailed numbers within the appendix.
Naturally, as a TDD workflow requires many extra turns and power calls, extra tokens will likely be used. Nevertheless, a lot of these will likely be cache hits, so be aware that the 3x or extra issue of tokens aren’t a direct illustration of how rather more expensive it’s. (Sadly, I did not monitor cache hits throughout the experiment.)
Immediate upkeep and testing
TDD is a course of that does not appear to “come pure” to fashions. It is like an uphill battle in opposition to the coaching knowledge, and takes a number of iterations on a immediate to get it to comply with the method more often than not. For instance, after I realised after my first batches that the agent did not do a lot refactoring within the red-green-refactor loop, I modified the immediate to place extra emphasis on that step, because it’s after all essential to TDD. I later requested Opus to have a look at these classes and see if it discovered an enchancment in refactoring efforts. It did report a rise in refactoring steps – nonetheless, it additionally listed some circumstances wherein the agent got down to refactor, however determined the design was ok even in circumstances the place Opus thought it clearly wasn’t (e.g. when every thing was carried out in a single huge module, however may have clearly been cut up up into a number of obligations).
TDD is a relatively complicated set of directions with numerous variables, and consequently numerous variations in how brokers interpret it. So I think about this kind of immediate to be much more risky throughout fashions than less complicated directions are, that means it takes effort to maintain the immediate working throughout fashions and mannequin releases.
My conclusions
I believe at this level there’s typically increasingly more proof that being overly particular about how we wish a mannequin to do one thing just isn’t a sustainable strategy. As a substitute, we must always discover as some ways as we are able to to observe the outcomes and provides suggestions. That suggestions must be automated wherever doable, and we have to fastidiously take into consideration the place we insert ourselves as arbiters of what’s good and proper.
Though I’m conscious that my little eval is much from representing a broad perspective on the effectiveness of TDD, it positively hasn’t given me any new indications that each one this effort is value it. Particularly not if we are able to discover different methods to realize nearly all of TDD advantages.
I personally have stopped telling my coding brokers to write down exams first, not to mention do TDD (which I by no means did, to be sincere), till I see evals or different robust arguments that persuade me in any other case. I am making an attempt to focus as an alternative on the advantages of TDD after I use it outdoors of the agent loop, and exploring alternative routes to realize them.
The right way to get good regression exams?
…in order that the agent and me get alerts when current performance breaks
I nonetheless care about strong regression exams, as a result of despite the fact that an agent can after all repair crimson exams the incorrect method round, at the least the crimson take a look at provides it a suggestions sign to double verify pre-existing necessities which may have damaged. I monitor and enhance regression high quality with the assistance of mutation testing, as an alternative of giving elaborate TDD directions and hoping for the most effective.
The right way to construct common refactoring into the method?
…in order that the codebase stays straightforward to vary
Refactoring stays essential, however the small steps of conventional TDD aren’t an environment friendly or efficient method to do it within the agent loop. Just a few examples of triggers for refactorings: Give the agent entry to static code evaluation; run common evaluations of construction and modularity; develop crew rituals to take care of an excellent understanding of the codebase and catch drift early; keep watch over the development of variety of information touched per change, and variety of tokens are for a change.
The right way to get confidence?
…in order that I’m not afraid to push to manufacturing
The toughest query stays, how will we get that confidence that TDD was giving us, how will we handle worry, how will we lock in progress? I haven’t got a transparent reply to that, however I am going to simply point out one of many issues that looks like an excellent constructing block for that: I’ve not too long ago tried out the Accepted Situations strategy that Ivett Ördög is advocating for. In my phrases (do not maintain her to it), it is a type of semi-manual testing that’s supported by a bespoke take a look at runner for every software. That runner reveals me practical take a look at eventualities in a simple to consider method, and permits me to “freeze” expectations (eventualities / fixtures) in that runner after I’ve totally confirmed them. Each time these frozen expectations are violated sooner or later, I’ve to approve them once more. My colleague Matteo Vaccari gave an excellent overview of his experiences with that strategy right here.
No matter finally ends up giving us belief and confidence in our software program sooner or later – I believe the function of TDD as we have recognized it’s considerably smaller than pre-GenAI.





