<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Domain driven development Archives - ShiftMag</title>
	<atom:link href="https://shiftmag.dev/tag/domain-driven-development/feed/" rel="self" type="application/rss+xml" />
	<link>https://shiftmag.dev/tag/domain-driven-development/</link>
	<description>Insightful engineering content &#38; community</description>
	<lastBuildDate>Thu, 18 Jul 2024 12:29:46 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://shiftmag.dev/wp-content/uploads/2024/08/cropped-ShiftMag-favicon-32x32.png</url>
	<title>Domain driven development Archives - ShiftMag</title>
	<link>https://shiftmag.dev/tag/domain-driven-development/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How I failed at Test-Driven Development and what it took to get it right</title>
		<link>https://shiftmag.dev/test-driven-development-fail-and-success-1118/</link>
		
		<dc:creator><![CDATA[Denis Kranjcec]]></dc:creator>
		<pubDate>Tue, 12 Sep 2023 07:30:00 +0000</pubDate>
				<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Dave Farley]]></category>
		<category><![CDATA[Domain driven development]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Test Driven Development]]></category>
		<guid isPermaLink="false">https://shiftmag.dev/?p=1118</guid>

					<description><![CDATA[<p>It took some time before I could say that TDD really works (for me). I don't think the problem was TDD, but my design and coding skills.</p>
<p>The post <a href="https://shiftmag.dev/test-driven-development-fail-and-success-1118/">How I failed at Test-Driven Development and what it took to get it right</a> appeared first on <a href="https://shiftmag.dev">ShiftMag</a>.</p>
]]></description>
										<content:encoded><![CDATA[<figure class="wp-block-post-featured-image"><img fetchpriority="high" decoding="async" width="1200" height="630" src="https://shiftmag.dev/wp-content/uploads/2023/08/TDD.png?x91379" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" style="object-fit:cover;" srcset="https://shiftmag.dev/wp-content/uploads/2023/08/TDD.png 1200w, https://shiftmag.dev/wp-content/uploads/2023/08/TDD-300x158.png 300w, https://shiftmag.dev/wp-content/uploads/2023/08/TDD-1024x538.png 1024w, https://shiftmag.dev/wp-content/uploads/2023/08/TDD-768x403.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>


<p>I&#8217;ve always liked the idea of test-driven development, and it&#8217;s three simple steps &#8211; write a test, make it pass, and refactor &#8211; but it took some time before I could say that TDD really works (for me). </p>



<p>I first heard about it over 20 years ago, probably when somebody talked about Kent Beck&#8217;s Extreme Programming:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>In XP, when possible, tests are written in advance of implementation.</p>



<p>If I am programming test-first, I write one failing test, make it work, and then write the next failing test.</p>
</blockquote>



<p>In <em>Growing Object-Oriented Software, Guided by Tests</em>,&nbsp;Steve Freeman and Nat Pryce further define it as follows:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>The cycle at the heart of TDD is: write a test; write some code to get it working; refactor the code to be as simple an implementation of the tested features as possible. Repeat.</p>
</blockquote>



<p><a href="https://www.youtube.com/watch?v=llaUBH5oayw&amp;list=PLwLLcwQlnXByqD3a13UPeT4SMhc3rdZ8q" target="_blank" rel="noreferrer noopener">Using TDD</a> should result in <strong>significantly fewer production bugs</strong> by having code that works as expected (in tests) and with <strong>better design and higher quality of the code</strong> (&#8220;easier to change&#8221;). The code should be <strong>modular, loosely coupled, cohesive, separate concerns well</strong>, and provide <strong>good encapsulation</strong>.</p>



<p>Dave Farley made it almost a haiku:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>The goal of TDD is:</p>



<p>Well Designed Code,</p>



<p>That We Know Works!</p>
</blockquote>



<h2 class="wp-block-heading"><span id="a-luke-warm-introduction-to-tdd">A luke-warm introduction to TDD</span></h2>



<p>Initially, I listened to and learned about TDD through conference sessions, online tutorials, and books, as well as trying it out in my (test) projects. I always got the &#8220;green bar,&#8221; but<strong> I didn&#8217;t think my code was significantly better than before</strong>, with tests written after the code.</p>



<p>One notable difference was that the code was testable (or at least more testable than before). But I didn&#8217;t see all the benefits I&#8217;ve read about.</p>



<p>Nevertheless, many authors, presenters, and software engineers I liked and learned other things from, and whose frameworks and libraries I used, kept talking about TDD and the many benefits they reaped from it.</p>



<p>So I kept at it, but every time, it didn&#8217;t feel like I was doing it correctly, and I definitely didn&#8217;t think I got the &#8220;advertised&#8221; results.</p>



<h2 class="wp-block-heading"><span id="my-mistake-taking-too-big-of-a-bite">My mistake: Taking too big of a bite</span></h2>



<p>Later, I started working on complex information systems, implementing complex business rules with a relatively small and stable team, where the developers were domain experts.</p>



<p>The ever-growing and ever-changing business rules made me more appreciative of a <strong>codebase that was easy to change</strong>, but that too often wasn&#8217;t the case with (my) code. At the time, we were writing some unit tests, more functional tests (actual use-case tests), and doing a decent continuous integration on most applications.</p>



<p>I refactored code daily to make it more readable and understandable. I mostly used rename/extract variable/method/class, and the code was better each time, but again, it wasn&#8217;t as easy to change as I would have liked it. The problem was that my <strong>object design wasn&#8217;t the best</strong>, and I tried to find a way to improve it. I also often tested implementation instead of functionality.</p>



<p>What helped bring me closer to TDD and up my object design <a href="https://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215/ref=sr_1_1?crid=3S0U1NQ94BFFN" target="_blank" rel="noreferrer noopener">Domain-Driven Design (DDD).</a> For me, the largest breakthrough came from internalizing the concepts of <a href="https://martinfowler.com/bliki/BoundedContext.html" target="_blank" rel="noreferrer noopener">bounded contexts</a> and <a href="https://martinfowler.com/bliki/UbiquitousLanguage.html" target="_blank" rel="noreferrer noopener">ubiquitous language</a>, but Entities, Value Objects, and Service Objects, including Aggregates, helped me with object design.&nbsp;</p>



<p>When I was writing code (in Java), influenced by DDD,<strong> the code was usually easier to understand</strong>, but the<strong> tests I wrote after the code were too hard to write and maintain.</strong> So, again, I tried TDD. Once again, my code was better, not to the full extent TDD enthusiasts raved about.</p>



<p>I later understood that my biggest mistake was that I wasn&#8217;t working in small steps, starting with the simplest (&#8220;boring&#8221;) use cases and building up to the more complex ones. The other mistake was that I didn&#8217;t refactor the code to &#8220;Well Designed Code,&#8221; so the <strong>methods and classes were too complex</strong> and coupled. The tests were simply too complex to set up and maintain.</p>



<p>And I&#8217;m not the only one who made that mistake, according to <a href="https://www.davefarley.net/?p=260" target="_blank" rel="noreferrer noopener">Dave Farley:</a></p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Over-complicating the solution is one of the commonest mistakes that I see TDD beginners make. They try to capture too much in one step. They prefer to have fewer more complex tests than many, small, simple tests that prod and probe at the behaviour of their system. The small steps, in thinking and in code, help a lot. Don’t be afraid of many small simple tests.</p>
</blockquote>



<h2 class="wp-block-heading"><span id="go-tdd-or-go-home">Go TDD or go home</span></h2>



<p>In the end, the circumstances pushed me all the way to TDD. I found myself in a situation where I had to maintain and further develop an application that processed billions of messages daily, had only a few tests, and had no access to developers who initially built it. It had complex and large classes and methods, scalability and reliability issues, and high hardware demands.</p>



<p>The only way to survive that was implementing much better code than I was doing before.</p>



<p>So, once again, I turned to books, videos, and courses about <a href="https://www.jbrains.ca/training/course/worlds-best-intro-to-tdd/" target="_blank" rel="noreferrer noopener">TDD</a>, <a href="https://martinfowler.com/articles/refactoring-2nd-ed.html" target="_blank" rel="noreferrer noopener">refactoring</a>, <a href="https://www.youtube.com/watch?v=tXTeLCwQZME" target="_blank" rel="noreferrer noopener">creating APIs</a>, and <a href="http://to%20https:/www.davefarley.net/?p=352" target="_blank" rel="noreferrer noopener">code quality</a> to improve my object design and its implementation.</p>



<p>This time, I implemented many (small?) changes in my designing and coding way of doing TDD:</p>



<ol class="wp-block-list" type="1" start="1">
<li>Working <a href="https://www.geepawhill.org/2021/09/29/many-more-much-smaller-steps-first-sketch/">in sm</a><a href="https://www.geepawhill.org/2021/09/29/many-more-much-smaller-steps-first-sketch/" target="_blank" rel="noreferrer noopener">a</a><a href="https://www.geepawhill.org/2021/09/29/many-more-much-smaller-steps-first-sketch/">ll, really small, steps</a> with a commit after each step (many 10s per day)</li>



<li>Stopping the <a href="https://ted.dev/articles/2023/05/30/your-classes-are-too-big-talk/" target="_blank" rel="noreferrer noopener">primitive obsession</a></li>



<li>Refactoring until the API design is good (&#8220;You are the first user of the API&#8221;) and tests are easy to write, understand, and maintain (&#8220;Tests are trying to tell you something&#8221;)</li>



<li>Doing <a href="https://shiftmag.dev/pair-programming-benefits-challenges-563/" target="_blank" rel="noreferrer noopener">pair programming</a></li>
</ol>



<p>I noticed significant changes in my code in a few months. It was <strong>simpler to understand,</strong> and the <strong>methods and classes were much shorter </strong>(but there were more classes). Adding new features wasn&#8217;t a challenge anymore, and other developers could help me in hours or, later, in minutes, <strong>without lengthy onboarding.</strong></p>



<p>With <a href="https://blog.thecodewhisperer.com/permalink/surviving-legacy-code-with-golden-master-and-sampling" target="_blank" rel="noreferrer noopener">Golden Master tests</a> and using TDD for new or changed and refactored code, soon there were enough tests and, as a result, confidence that <strong>changes to the code won&#8217;t carry any significant risk.</strong></p>



<p>In that short time, using TDD daily, I got very predictive and almost constant progress in the right direction with my coding, and I could provide value to my users better and faster.&nbsp;</p>



<h2 class="wp-block-heading">It wasn&#8217;t TDD; it was me</h2>



<p>In retrospect, I think that my problem with getting better code with TDD was in my design and coding skills, not in TDD. Not that they were particularly bad &#8211; I did manage to create and maintain large, complex, and successful applications/systems.</p>



<p>But <strong>I missed some (or many?) details that make TDD something people rave about</strong>. If you have the chance, find someone good at TDD and <a href="https://shiftmag.dev/pair-programming-benefits-challenges-563/" target="_blank" rel="noreferrer noopener">pair program</a> with them for a few days to see if it works for you.</p>



<p>What was your turning point in using TDD and getting good results? Please share your experience with me on&nbsp;<a href="https://twitter.com/kranjcec">Twitter</a>&nbsp;or&nbsp;<a href="https://www.linkedin.com/in/kranjcec/">LinkedIn</a>!&nbsp;</p>
<p>The post <a href="https://shiftmag.dev/test-driven-development-fail-and-success-1118/">How I failed at Test-Driven Development and what it took to get it right</a> appeared first on <a href="https://shiftmag.dev">ShiftMag</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 

Served from: shiftmag.dev @ 2026-05-01 02:47:14 by W3 Total Cache
-->