{"id":3606,"date":"2026-05-18T14:46:59","date_gmt":"2026-05-18T13:46:59","guid":{"rendered":"https:\/\/www.smharter.com\/blog\/?p=3606"},"modified":"2026-05-19T11:20:07","modified_gmt":"2026-05-19T10:20:07","slug":"ai-coding-test-first-vs-test-after-pros-cons","status":"publish","type":"post","link":"https:\/\/www.smharter.com\/blog\/2026\/05\/18\/ai-coding-test-first-vs-test-after-pros-cons\/","title":{"rendered":"AI Coding Test-first Vs Test-after: pros &amp; cons"},"content":{"rendered":"\n<p>I am a long-time enthusiast and expert of test-first TDD, and A-TDD.<br><br>As part of the task of reimagining how we code with AI, I am reflecting with openness and curiosity on my experience with AI-assisted coding (human-driven, agentic, frequently reviewed AI-generated code) adopted to create production-grade software.<br><br>Specifically, in this post, I document the pros and cons I have observed in the test-first and test-after approaches when used with AI-assisted coding.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Structural changes AI coding brings to testing<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Intent<\/strong>: The Test-first approach drives developers to clarify code intent and make design decisions, one test at a time. When pairing with an AI, the developer already does that every time they write a good prompt to generate code, regardless of the Test-first or&nbsp;Test-after approach.<br><\/li>\n\n\n\n<li><strong>Simple design &amp; reusable code<\/strong>:\n<ul class=\"wp-block-list\">\n<li>AI generates tests in batches, eliminating the Test-first traditional Red-Green-Refactor micro-cycles that ensure simple implementation code and protect against false positives.<br><\/li>\n\n\n\n<li>Frequent AI-generated code reviews encompass both code and design refactoring.<br><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Behaviour documentation<\/strong>: no major differences here.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">My own conclusions<\/h2>\n\n\n\n<p>Let&#8217;s start from the end. So far, these are my conclusions following from the  Pros and Cons I have experienced in my own context. <br><br>Unlike before in manual coding, where test-first is a clear winner, now in mid-2026, I don&#8217;t see a clear winner between <strong>AI-Test-first<\/strong> and <strong>AI-Test-after<\/strong>. Both seem valid options, each with its pros and cons. Further evolution of LLMs&#8217; capabilities is likely to change this.<br><br><strong>A Sr software engineer experienced in TDD and A-TDD<\/strong>, who naturally adopts the A-TDD and TDD way of thinking about behaviour and code design already when writing each prompt, may benefit from the pros of <strong>AI-Test-after<\/strong> while countering the cons with an additional step in which they direct the AI to perform mutation testing, fault injection, or adversarial verification.<br><br><strong>A Jr software engineer, and everyone without ingrained TDD and A-TDD habits,<\/strong> may benefit from the guidance along the TDD and A-TDD way of thinking coming from following the <strong>AI-Test-first<\/strong> and its pros in code design quality (resulting from code generation after generating the tests) and test reliability.<br><br>Keep reading my list of pros and cons; you can use it as inspiration to reflect on the pros and cons that apply to you and your context, compare and contrast.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Test-first and Test-after: the Pros and Cons I experienced<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>About Testable code (modular design, dependency inversion, etc.):<\/strong><br>    \n<ul class=\"wp-block-list\">\n<li><strong>AI-Test-first<\/strong> generates testable code and architecture and helps less experienced developers to methodically adopt the A-TDD and TDD way of thinking about behaviour and code design, maintaining sight of the important design decisions.<br>   <\/li>\n\n\n\n<li><strong>With AI-Test-after,<\/strong> I direct the code behaviour and design with specific instructions in the prompt (instead of the tests); I further refine the design as necessary, with quick manual or AI-generated small refactorings during the code review step. I find this approach faster and more effective for me as I gain speed without losing quality.<br>   <\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>The Asymmetric AI Efficiency (Rapid tests-after generation):<\/strong><br>\n<ul class=\"wp-block-list\">\n<li><strong>With AI-Test-after, <\/strong>I have found LLMs extremely efficient at generating good-enough tests against existing code, with little instruction, giving me a huge productivity advantage compared to AI-Test-first.<br>   <\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>AI micro-management Trap (for unit tests):<\/strong><br>   \n<ul class=\"wp-block-list\">\n<li><strong>In AI-Test-first,<\/strong> the prompt for generating granular unit tests (before the implementation code) requires a lot of detail; writing such a prompt is very time-consuming, and not too far from manually writing the unit tests.<br>    <\/li>\n\n\n\n<li><strong>With AI-Test-after<\/strong>, it is enough to reference the class or module and ask in the prompt to generate the unit tests. Voil\u00e0.<br>   <\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>High Friction:<\/strong><br>    \n<ul class=\"wp-block-list\">\n<li><strong>With AI-Test-first, <\/strong>the generated tests are more prone to small, time-consuming, hard-to-detect issues, such as using deprecated test framework functions, subtle mocking errors, wrong interface or implementation assumptions.<br><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Increased Cognitive Overhead<\/strong>:<br>        \n<ul class=\"wp-block-list\">\n<li><strong>With AI-Test-first<\/strong>, spotting a problem in the generated tests, identifying the root cause, and fixing it often involves a triple conceptual indirection: Prompt =&gt; Test =&gt; Implementation code (yet to be generated). In general, it tends to require more time, attention and a higher cognitive effort.<br>      <\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>The \u201cDouble Hallucination\u201d Trap<\/strong>:<br>   \n<ul class=\"wp-block-list\">\n<li><strong>With AI-Test-after, <\/strong>a hallucination can introduce a bug in the implementation code; later, the generated test may mirror the bug as intended behaviour. The generated test code may not cover all possible execution paths or return false positives. Furthermore, LLMs may not spot complex domain properties, existing semantic gaps, non-explicit invariants, and non-obvious failure modes; as a result, they may not generate tests for these.<br><br>To counter these weaknesses, it is useful to take an additional step by directing the AI to perform mutation testing, fault injection, or adversarial verification.<br><br><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><strong>Which Pros and Cons have you experienced in your own context?<\/strong><\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-image\"><figure class=\"alignright size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.smharter.com\/blog\/wp-content\/uploads\/develop.png\" alt=\"\" class=\"wp-image-2071\" width=\"260\" height=\"330\"\/><\/figure><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"text-ads\">\n\t<h3>Develop Technical Excellence that delivers.<\/h3>\n\t<p>\n\t<br>\n\tSee how we can help.\n\t<br>\n\tYou, your team, your Tech.\n\t<br>\n\t<br>\n\t<\/p>\n\n\t<div class=\"local-scroll\">\n\t\t<a href=\"\/coaching.html#one_session\" target=\"_blank\" class=\" btn elastic-btn-mod btn-mod btn-dark btn-medium btn-round\" onclick=\"ga('send','event','Blog tech-ads','Click one_session button','Virtual Tech Mentoring');\" rel=\"noopener noreferrer\">\n\t\tVirtual Tech Mentoring\n\t\t<\/a> \n\t\t<a href=\"\/coaching.html#assessments\" target=\"_blank\" class=\"btn elastic-btn-mod btn-mod btn-dark btn-medium btn-round\" onclick=\"ga('send','event','Blog tech-ads','Click assessments button','Virtual Tech Assessments');\" rel=\"noopener noreferrer\">\n\t\tVirtual Tech Assessments\n\t\t<\/a>\n\t<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Test-First is a clear winner in manual coding. But how does AI-assisted development shift the pros and cons and change the balance between Test-First and Test-After?<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-3606","post","type-post","status-publish","format-standard","hentry","category-ai-assisted-coding"],"_links":{"self":[{"href":"https:\/\/www.smharter.com\/blog\/wp-json\/wp\/v2\/posts\/3606","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.smharter.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.smharter.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.smharter.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.smharter.com\/blog\/wp-json\/wp\/v2\/comments?post=3606"}],"version-history":[{"count":14,"href":"https:\/\/www.smharter.com\/blog\/wp-json\/wp\/v2\/posts\/3606\/revisions"}],"predecessor-version":[{"id":3622,"href":"https:\/\/www.smharter.com\/blog\/wp-json\/wp\/v2\/posts\/3606\/revisions\/3622"}],"wp:attachment":[{"href":"https:\/\/www.smharter.com\/blog\/wp-json\/wp\/v2\/media?parent=3606"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.smharter.com\/blog\/wp-json\/wp\/v2\/categories?post=3606"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.smharter.com\/blog\/wp-json\/wp\/v2\/tags?post=3606"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}