<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title>Chemaclass - tdd</title><subtitle>Tech Lead sharing practical insights on software craftsmanship, TDD, leadership, Bitcoin, and AI. Blog posts, book summaries, and conference talks.</subtitle><link rel="self" type="application/atom+xml" href="https://chemaclass.com/tags/tdd/atom.xml"/><link rel="alternate" type="text/html" href="https://chemaclass.com"/><generator uri="https://www.getzola.org/">Zola</generator><updated>2024-10-30T00:00:00+00:00</updated><id>https://chemaclass.com/tags/tdd/atom.xml</id><entry xml:lang="en"><title>bashunit</title><subtitle>Turning frustrations into tools for better development</subtitle><category term="bashunit" scheme="https://chemaclass.com/tags/bashunit/" label="Bashunit"/><category term="bash" scheme="https://chemaclass.com/tags/bash/" label="Bash"/><category term="testing" scheme="https://chemaclass.com/tags/testing/" label="Testing"/><category term="open-source" scheme="https://chemaclass.com/tags/open-source/" label="Open Source"/><category term="tdd" scheme="https://chemaclass.com/tags/tdd/" label="Tdd"/><published>2024-10-30T00:00:00+00:00</published><updated>2024-10-30T00:00:00+00:00</updated><author><name>
Chemaclass</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/blog/bashunit/"/><id>https://chemaclass.com/blog/bashunit/</id><summary type="html">bashunit is a lightweight, easy-to-use testing framework for Bash, packed with handy features like parallel and snapshot testing, test doubles, data providers, and tons of built-in assertions. Backed by clear docs and an active community, it's become a favorite for reliable Bash testing. What started as a simple dev frustration has grown into an open-source tool that makes testing in Bash a lot easier and fun.</summary><content type="html">&lt;p>bashunit is a lightweight, easy-to-use testing framework for Bash. Features like parallel and snapshot testing, test doubles, data providers, and tons of built-in assertions.&lt;/p>
&lt;span id="continue-reading">&lt;/span>
&lt;p>Backed by clear docs and an active community, it’s become a favorite for reliable Bash testing. What started as a simple dev frustration has grown into an open-source tool that makes testing in Bash a lot easier and fun.&lt;/p>
&lt;ol>
&lt;li>The story behind bashunit&lt;/li>
&lt;li>Why create another testing library?&lt;/li>
&lt;li>How is it nowadays?&lt;/li>
&lt;li>Core features&lt;/li>
&lt;li>Lightning tech talk&lt;/li>
&lt;/ol>
&lt;h2 id="the-story-behind-bashunit">The story behind bashunit
&lt;a class="heading-anchor" href="#the-story-behind-bashunit" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>The journey to create bashunit started from a simple frustration: I worked with a team where each commit had to start with the ticket name. Since I like working in small steps with quick, iterative commits, adding the ticket key and number to every single commit became a major hurdle, slowing down my development flow with unnecessary friction.&lt;/p>
&lt;p>After a few days of this, I decided to automate it. Git has a helpful hook, &lt;code>prepare-commit-msg&lt;/code>, which allows you to alter commit messages before they’re finalized. I created a Bash (&lt;a rel="external" href="https://github.com/Chemaclass/conventional-commits/blob/main/git-hooks/prepare-commit-msg.sh">script&lt;/a>) that automatically fetches the ticket key and number from the branch name and inserts it into the commit message, making my process smoother and more efficient.&lt;/p>
&lt;p>As someone who values continuous improvement, I began adding more features to this script. However, it became clear that maintaining and testing these changes manually was taking too long and was prone to error. To make development safer and more efficient, I created an &lt;code>assert&lt;/code>(&lt;a rel="external" href="https://github.com/Chemaclass/conventional-commits/blob/705489a3487a4607183090d5574827bf6fedabda/git-hooks/prepare-commit-msg_test.sh">link&lt;/a>) function, enabling automated tests that verified the expected behavior based on script output.&lt;/p>
&lt;p>&lt;img src="/images/blog/2024-10-30/bashunit-original-assert.jpg" alt="bashunit-original-assert.jpg" />&lt;/p>
&lt;p>The &lt;code>assert&lt;/code> function allowed me to define multiple assertions in a separate file, making it easy to validate that any refactoring of the original hook maintained the expected behavior. If a change inadvertently broke existing functionality, it would instantly flag the issue, letting me know right away that something needed fixing. This setup provided immediate feedback and helped ensure that any updates to the script didn’t disrupt its intended logic. For example:&lt;/p>
&lt;p>&lt;img src="/images/blog/2024-10-30/conventional-commits-original-tests.jpg" alt="conventional-commits-original-tests.jpg" />&lt;/p>
&lt;p>In the example above, you’ll notice that I execute the actual “&lt;code>SCRIPT&lt;/code>” as the second argument in the assert function, comparing its output to the expected value provided as the first argument. Here, we have two test cases, each exporting &lt;code>TEST_BRANCH&lt;/code> to simulate how the commit message would vary based on the branch name. This setup emulates real behavior, allowing us to test how different branch names affect the commit message formatting. More examples &lt;a rel="external" href="https://github.com/Chemaclass/conventional-commits/blob/27aeebe4e76afe0a2e91cba85537399eab112eb4/test/prepare-commit-msg_test.sh">here&lt;/a>.&lt;/p>
&lt;p>I decided to separate the &lt;code>assert&lt;/code> function from the test cases, as shown &lt;a rel="external" href="https://github.com/Chemaclass/conventional-commits/commit/5458e5728296bb94b1e8e6b25eeccde6cc700589">here&lt;/a>, to keep things modular and reusable. Then, I created a &lt;code>runner&lt;/code> to execute each test case independently, reducing test interference and improving reliability. You can see that setup &lt;a rel="external" href="https://github.com/Chemaclass/conventional-commits/commit/92a5880d7f26b3422de6b91b51c04f9ff7b961fd">here&lt;/a>. This structure made automated testing easier and refactoring safer.&lt;/p>
&lt;p>&lt;img src="/images/blog/2024-10-30/conventional-commits-call_test_functions.jpg" alt="conventional-commits-call_test_functions.jpg" />&lt;/p>
&lt;p>This was a great improvement because it made it easier to separate &lt;a rel="external" href="https://github.com/Chemaclass/conventional-commits/blob/4c7dae8d44d425ff06fbb48654388f90c2beb3c4/tests/prepare-commit-msg_test.sh">test cases&lt;/a> from the logic of the test runner itself. This clear structure has simplified both creating and managing tests.&lt;/p>
&lt;p>&lt;img src="/images/blog/2024-10-30/conventional-commits-refactor-test-cases.webp" alt="conventional-commits-refactor-test-cases.jpg" />&lt;/p>
&lt;p>Now the tests were organized and I got an &lt;a rel="external" href="https://github.com/Chemaclass/conventional-commits/commit/f459f43cecc271becb1e5eb6ca95d24c97e87830">idea&lt;/a>:&lt;/p>
&lt;p>&lt;img src="/images/blog/2024-10-30/bashunit-idea.jpg" alt="bashunit idea note" />&lt;/p>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="markdown">&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);font-weight: bold;">##&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);font-weight: bold;"> Follow-up idea&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>Separate the testing logic into another repo, &lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>so it could be reused anywhere.&lt;/span>&lt;/span>&lt;/code>&lt;/pre>
&lt;p>And so it &lt;a rel="external" href="https://github.com/TypedDevs/bashunit/commit/27269c21c8d0b03bcb3f2000767f4a27b8bf08a1">began&lt;/a>. At the time, I didn’t know much about Bash or the best ways to use a Bash project as a dependency. But I knew I could start by using a Git submodule, even though I’m not a huge fan of them.&lt;/p>
&lt;p>On September 4, 2023, I launched version &lt;a rel="external" href="https://github.com/TypedDevs/bashunit/commit/fc9aac40eb8e5ad4483f08d79eb678a3650dcf78">0.1&lt;/a>, which featured a working runner and a single assertion function: &lt;code>assertEquals&lt;/code>. Later, version &lt;a rel="external" href="https://github.com/TypedDevs/bashunit/releases/tag/0.2.0">0.2&lt;/a> was released, allowing &lt;code>./bashunit&lt;/code> to be a standalone executable, runnable from any folder. Here’s how it looked back then:&lt;/p>
&lt;p>&lt;img src="/images/blog/2024-10-30/bashunit-02-demo.jpg" alt="bashunit-02-demo.jpg" />&lt;/p>
&lt;p>I shared the project with a few friends who quickly jumped in to help with documentation, the website, additional assertions, snapshot testing, and key decisions. To emphasize its open-source spirit and community ownership, I moved it to an organization we created specifically for sharing OSS projects, making it a truly collaborative project rather than an individual one.&lt;/p>
&lt;h2 id="why-create-another-testing-library">Why create another testing library?
&lt;a class="heading-anchor" href="#why-create-another-testing-library" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>I know now that other Bash testing libraries exist. But when I started with bashunit, I wasn’t aware of them, and frankly, I’m still no Bash expert. By the time I learned about these alternatives, it was already too late, bashunit had gained enough momentum and excitement to keep going strong.&lt;/p>
&lt;p>While those other libraries may serve specific use cases, use modern Bash, or be developed by more seasoned Bash developers, bashunit aims to set itself apart by offering a great developer experience, shaped by years of working with various testing frameworks.&lt;/p>
&lt;p>I was asked about the differences on September 7, 2023, and here’s my response:
&lt;a rel="external" href="https://github.com/TypedDevs/bashunit/issues/8">Question: Difference to pgrange/bash_unit&lt;/a>.&lt;/p>
&lt;h2 id="how-is-it-nowadays">How is it nowadays?
&lt;a class="heading-anchor" href="#how-is-it-nowadays" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Today, you can &lt;a rel="external" href="https://bashunit.typeddevs.com/installation">install&lt;/a> bashunit via curl, Homebrew, MacPorts, by downloading the latest GitHub &lt;a rel="external" href="https://github.com/TypedDevs/bashunit/releases">release from GitHub&lt;/a>, or even by &lt;a rel="external" href="https://github.com/TypedDevs/bashunit/blob/main/build.sh">building it yourself&lt;/a> from source. Completely open-source.&lt;/p>
&lt;p>The project is written in Bash 3.2 (from 2007) since that’s the default version on macOS, even now, in 2024. This compatibility means bashunit runs smoothly on that version, and I plan to maintain support for it.&lt;/p>
&lt;p>To ensure quality, we test each feature with unit, functional, and acceptance tests, making bashunit its own “first user” of every new feature. We also have several CI workflows using &lt;a rel="external" href="https://github.com/TypedDevs/bashunit/actions/workflows/tests.yml">GitHub actions&lt;/a> that run tests on different platforms to check compatibility and confirm everything works as promised.&lt;/p>
&lt;p>&lt;img src="/images/blog/2024-10-30/bashunit-ci.jpg" alt="bashunit-ci.jpg" />&lt;/p>
&lt;p>In June 2024, bashunit was &lt;a rel="external" href="https://bashunit.typeddevs.com/blog/2024-06-21-phpstan-integration">integrated in PHPStan&lt;/a> for their end-to-end tests, enabling the use of bashunit’s assertions independently of its runner. This flexibility turned out to be very useful.&lt;/p>
&lt;p>Last summer, I was invited to speak about bashunit at the &lt;a href="/talks/#may">International PHP Conference&lt;/a> in Berlin, alongside &lt;a rel="external" href="https://emmanuelvalverde.dev/">Manu&lt;/a>, another contributor. This project has opened doors and led to a lot of gratitude from users who appreciate the work we’ve put into it.&lt;/p>
&lt;h2 id="core-features">Core features
&lt;a class="heading-anchor" href="#core-features" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>bashunit includes classic lifecycle functions like &lt;code>set_up&lt;/code>, &lt;code>tear_down&lt;/code>, &lt;code>set_up_before_script&lt;/code>, and &lt;code>tear_down_after_script&lt;/code>.&lt;/p>
&lt;p>It also supports a wide range of &lt;a rel="external" href="https://bashunit.typeddevs.com/command-line">command-line parameters&lt;/a>
and &lt;a rel="external" href="https://bashunit.typeddevs.com/configuration">configuration values&lt;/a>. Some of my favorites include:&lt;/p>
&lt;ul>
&lt;li>&lt;code>--parallel&lt;/code>&lt;/li>
&lt;li>&lt;code>--filter&lt;/code>&lt;/li>
&lt;li>&lt;code>--stop-on-failure&lt;/code>&lt;/li>
&lt;li>&lt;code>--verbose&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>We also provide &lt;a rel="external" href="https://bashunit.typeddevs.com/data-providers">data providers&lt;/a> for running the same test cases with different inputs.&lt;/p>
&lt;p>For &lt;a rel="external" href="https://bashunit.typeddevs.com/test-doubles">test doubles&lt;/a>, bashunit offers mocks and spies. These work within the same process as the test, but currently, they don’t work across processes, an area for improvement.&lt;/p>
&lt;p>Powerful &lt;a rel="external" href="https://bashunit.typeddevs.com/snapshots">snapshot testing&lt;/a> is included, making it easy to verify command or script outputs over time.&lt;/p>
&lt;p>bashunit offers a large set of native &lt;a rel="external" href="https://bashunit.typeddevs.com/assertions">assertions&lt;/a> for test cases, including:&lt;/p>
&lt;ul>
&lt;li>&lt;code>assert_same&lt;/code>&lt;/li>
&lt;li>&lt;code>assert_equals&lt;/code>&lt;/li>
&lt;li>&lt;code>assert_contains&lt;/code>&lt;/li>
&lt;li>&lt;code>assert_matches&lt;/code>&lt;/li>
&lt;li>&lt;code>assert_string_starts_with&lt;/code>&lt;/li>
&lt;li>&lt;code>assert_array_contains&lt;/code>&lt;/li>
&lt;li>&lt;code>assert_successful_code&lt;/code>&lt;/li>
&lt;li>&lt;code>assert_general_error&lt;/code>&lt;/li>
&lt;li>&lt;code>assert_file_exists&lt;/code>&lt;/li>
&lt;li>&lt;code>assert_file_contains&lt;/code>&lt;/li>
&lt;li>&lt;code>assert_match_snapshot&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>You can even create your own &lt;a rel="external" href="https://bashunit.typeddevs.com/custom-asserts">custom asserts&lt;/a> to extend bashunit’s capabilities.&lt;/p>
&lt;p>With over &lt;strong>25&lt;/strong> contributors and more than &lt;strong>325&lt;/strong> stars on GitHub within just a year of spare-time development, I’m genuinely proud of what this project has become.&lt;/p>
&lt;h2 id="lightning-tech-talk">Lightning tech talk
&lt;a class="heading-anchor" href="#lightning-tech-talk" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Recently, I presented a lightning tech talk at a hackers’ meetup, demoing bashunit to an audience of over 100 people. It was an incredible experience to share this tool with such an engaged crowd!&lt;/p>
&lt;div style="position:relative;aspect-ratio:16/9;width:100%;">
&lt;iframe
src="https://www.youtube-nocookie.com/embed/SX7iNHaSsF0"
title="YouTube video"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
referrerpolicy="strict-origin-when-cross-origin"
style="position:absolute;inset:0;width:100%;height:100%;border:0;"
allowfullscreen>
&lt;/iframe>
&lt;/div>
&lt;hr />
&lt;p>bashunit original logo designed by &lt;a rel="external" href="https://antonio.gg/">Antonio&lt;/a>.&lt;/p></content></entry><entry xml:lang="en"><title>Effective Pair Programming</title><subtitle>Embracing quality practices in your engineering culture</subtitle><category term="pair-programming" scheme="https://chemaclass.com/tags/pair-programming/" label="Pair Programming"/><category term="xp" scheme="https://chemaclass.com/tags/xp/" label="Xp"/><category term="tdd" scheme="https://chemaclass.com/tags/tdd/" label="Tdd"/><category term="communication" scheme="https://chemaclass.com/tags/communication/" label="Communication"/><category term="clean-code" scheme="https://chemaclass.com/tags/clean-code/" label="Clean Code"/><published>2024-03-28T00:00:00+00:00</published><updated>2024-03-28T00:00:00+00:00</updated><author><name>
Chemaclass</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/blog/effective-pair-programming/"/><id>https://chemaclass.com/blog/effective-pair-programming/</id><summary type="html">A practical guide to pair programming that works: roles, rotation, when to pair, common pitfalls, and how to make sessions productive.</summary><content type="html">&lt;p>What is pair programming? Two people working together on the same problem, at the same time.&lt;/p>
&lt;span id="continue-reading">&lt;/span>
&lt;p>It is not about one person showing off their skills in front of another, nor one person afraid of making mistakes due to an impostor syndrome.&lt;/p>
&lt;p>Each person will have a role:&lt;/p>
&lt;ul>
&lt;li>Navigator: he will pay attention to the bigger picture; eg: architecture, relation between collaborators, object design, etc.&lt;/li>
&lt;li>Driver: she will pay attention to the small details; eg: naming, code conventions, writing syntax, object design, etc.&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>The pair could, and should, switch roles occasionally; eg: every X commits pushed, every 10 mins, … up to them.&lt;/p>
&lt;/blockquote>
&lt;p>Pair programming should not be considered a practice only for “seniors” to juniors, but regardless of the team members’ experience level.&lt;/p>
&lt;p>It is about the &lt;strong>collaboration flow&lt;/strong>, the quality communication, the absence of feeling judged, and the idea of welcoming vulnerability with your peers, knowing they will support and help you.&lt;/p>
&lt;p>It is about constantly challenging each other, seeking the most pragmatic solution while keeping it simple. Always looking for &lt;strong>quick feedback&lt;/strong> when speaking to each other, but also on the solution you agreed to implement and its direction.&lt;/p>
&lt;p>It is about the short, quick, and immediate feedback loop while talking to your partner, who &lt;strong>reviews your code on the fly&lt;/strong>. You can guide as a navigator or help the driver validate their ideas in a broader picture.&lt;/p>
&lt;p>It is about the constant &lt;strong>sharing&lt;/strong> of &lt;strong>knowledge&lt;/strong> atmosphere by default, reducing bus-factors and silo-knowledge areas to the maximum. Increasing the focus by having two minds working on the same task simultaneously.&lt;/p>
&lt;p>It is about &lt;strong>team cohesion&lt;/strong> and sharpening the feeling that we belong. When we understand each other’s strengths and weaknesses, we will realize how much we can help each other grow.&lt;/p>
&lt;p>&lt;img src="/images/blog/2024-03-28/footer.webp" alt="blog-img" />&lt;/p>
&lt;h2 id="how-can-you-practice-pair-programming">How can you practice pair programming?
&lt;a class="heading-anchor" href="#how-can-you-practice-pair-programming" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Pair programming can be done in different ways:&lt;/p>
&lt;ul>
&lt;li>You can start and finish a task with pairing. You can time-box it to 30, 60, 90 minutes. Either way, it is recommended to have pauses in the middle - Pomodoro.&lt;/li>
&lt;li>You can start the task together and stop when one of your peers feels confident enough to continue alone.&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>It is up to the team, and the task in context, to decide when and how to apply pairing to get the best out of it.&lt;/p>
&lt;/blockquote>
&lt;p>This does not mean you must constantly work “no matter what” in pair. This is not about creating rules; on the contrary, it is about embracing this practice to the point you feel confident to choose when and how to use it to get the best out of it.&lt;/p>
&lt;p>Pair programming might become one of the best tools in your team toolbox for daily interactions. Not because you read it somewhere but because of the benefits you and your team will find.&lt;/p>
&lt;h3 id="common-patterns">Common Patterns
&lt;a class="heading-anchor" href="#common-patterns" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;h4 id="different-strategies-for-effective-pairing">Different strategies for effective pairing
&lt;a class="heading-anchor" href="#different-strategies-for-effective-pairing" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h4>
&lt;ul>
&lt;li>&lt;strong>Driver-Navigator&lt;/strong>: One person is driving the code (with the keyboard), focusing on the detail aspect of the task itself. The other is a navigator (no keyboard), having a more abstract picture of the task in mind.&lt;/li>
&lt;li>&lt;strong>Ping-Pong&lt;/strong>: Frequent switching driver-navigator roles in small interactions, e.g., every N minutes, every N commits, etc.&lt;/li>
&lt;li>&lt;strong>Backseat driver&lt;/strong>: The navigator engages actively with the driver.&lt;/li>
&lt;li>&lt;strong>Tourist guide&lt;/strong>: The navigator passively learns with the driver.&lt;/li>
&lt;/ul>
&lt;p>&lt;img src="/images/blog/2024-03-28/good-pair-prog.jpg" alt="effective pair programming patterns" />&lt;/p>
&lt;h4 id="anti-patterns-while-pairing">Anti-patterns while pairing
&lt;a class="heading-anchor" href="#anti-patterns-while-pairing" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h4>
&lt;ul>
&lt;li>&lt;strong>The silent partner&lt;/strong>: The navigator is not participating, and they are being silent.&lt;/li>
&lt;li>&lt;strong>The solo act&lt;/strong>: The driver ignores all inputs from the navigator.&lt;/li>
&lt;li>&lt;strong>Distracted pair&lt;/strong>: The pair does not focus on the problem to solve.&lt;/li>
&lt;li>&lt;strong>The Dictator&lt;/strong>: One person is telling what to do, ignoring the input from the other.&lt;/li>
&lt;li>&lt;strong>Philosophical pair&lt;/strong>: The pair is &lt;a href="/blog/bikeshedding/">bikeshedding&lt;/a> into irrelevant topics.&lt;/li>
&lt;li>&lt;strong>The code war&lt;/strong>: The pair does not reach an agreement and starts an unnecessary war, which wastes time and effort.&lt;/li>
&lt;/ul>
&lt;p>&lt;img src="/images/blog/2024-03-28/anti-pair-prog.jpg" alt="pair programming anti-patterns" />&lt;/p>
&lt;p>&lt;strong>Want more?&lt;/strong> Check this out: &lt;a rel="external" href="https://www.figma.com/file/FCmGwRPIO8cLowDRraJhgr/Learning-TDD">Learning Through KATAS&lt;/a>&lt;/p>
&lt;p>&lt;img src="/images/blog/2024-03-28/learning-through-katas.jpg" alt="learning through katas" />&lt;/p>
&lt;h2 id="the-takeaway">The takeaway
&lt;a class="heading-anchor" href="#the-takeaway" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Pairing is not a rule to enforce, it is a tool to reach for. Use it when the task is complex, the knowledge is siloed,
or the stakes are high. Skip it when the work is trivial. The goal is never “always pair”, it is &lt;strong>better software and a
stronger team&lt;/strong>. Pick one real task this week, pair on it, and switch roles often. The benefits show up faster than you
expect.&lt;/p>
&lt;aside class="kudos">
&lt;span class="kudos__icon" aria-hidden="true">🧠&lt;/span>
&lt;div class="kudos__content">
&lt;p>Thanks to my friend &lt;a rel="external" href="https://x.com/evrtrabajo">Manu&lt;/a>, who helped me with this post. We even share a &lt;a rel="external" href="https://phpconference.com/agile-culture/practical-tdd-workshop/">workshop&lt;/a> on this topic.&lt;/p>
&lt;/div>
&lt;/aside></content></entry><entry xml:lang="en"><title>How to Test Private Methods?</title><subtitle>Testing private methods. When and how?</subtitle><category term="testing" scheme="https://chemaclass.com/tags/testing/" label="Testing"/><category term="tdd" scheme="https://chemaclass.com/tags/tdd/" label="Tdd"/><category term="software-design" scheme="https://chemaclass.com/tags/software-design/" label="Software Design"/><category term="clean-code" scheme="https://chemaclass.com/tags/clean-code/" label="Clean Code"/><published>2023-10-20T00:00:00+00:00</published><updated>2023-10-20T00:00:00+00:00</updated><author><name>
Chemaclass</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/blog/how-to-test-private-methods/"/><id>https://chemaclass.com/blog/how-to-test-private-methods/</id><summary type="html">From time to time I have had to face this question: how to test private methods? I have put together in an article the techniques that I usually use.</summary><content type="html">&lt;p>This is a question that I have encountered with some frequency for a long time. So I thought I would put together my thoughts on the subject here.&lt;/p>
&lt;span id="continue-reading">&lt;/span>&lt;h2 id="short-answer">Short answer
&lt;a class="heading-anchor" href="#short-answer" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Never.&lt;/p>
&lt;h2 id="long-answer">Long answer
&lt;a class="heading-anchor" href="#long-answer" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Never ever.&lt;/p>
&lt;hr />
&lt;h2 id="what-if">What if…?
&lt;a class="heading-anchor" href="#what-if" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>If you really want to test a private method, consider extracting that private method logic into a separate class, and write a unit test for that class’ behavior.&lt;/p>
&lt;blockquote>
&lt;p>For this one, I was inspired by Fran Iglesias’ &lt;a rel="external" href="https://franiglesias.github.io/test-private-methods/">original post&lt;/a>.&lt;/p>
&lt;/blockquote></content></entry><entry xml:lang="en"><title>Dedicated QA Teams in Software?</title><subtitle>How does it fit a dedicated QA person in your agile team?</subtitle><category term="testing" scheme="https://chemaclass.com/tags/testing/" label="Testing"/><category term="tdd" scheme="https://chemaclass.com/tags/tdd/" label="Tdd"/><category term="agile" scheme="https://chemaclass.com/tags/agile/" label="Agile"/><category term="clean-code" scheme="https://chemaclass.com/tags/clean-code/" label="Clean Code"/><published>2023-05-17T00:00:00+00:00</published><updated>2023-05-17T00:00:00+00:00</updated><author><name>
Chemaclass</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/blog/dedicated-qa-teams/"/><id>https://chemaclass.com/blog/dedicated-qa-teams/</id><summary type="html">This will be controversial, but let's talk about the QA position. The hidden truth behind the lack of software quality and why this should concern you if you write software.</summary><content type="html">&lt;p>This will be controversial, but let’s talk about the QA position. The hidden truth behind the lack of software quality and why this should concern you if you write software.&lt;/p>
&lt;span id="continue-reading">&lt;/span>&lt;h2 id="qa-is-a-role-not-a-position">QA is a role, not a position
&lt;a class="heading-anchor" href="#qa-is-a-role-not-a-position" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>As a software developer, when you write software, you are responsible for the quality of whatever you’re writing. A third person acting like QA could find that your solution doesn’t work like expected, but how come? You might argue they might catch edge cases, but how could that be possible if the software was already tested previously?&lt;/p>
&lt;p>A software team’s final goal is to make the QA position useless because they should find nothing but well-working software. But how do you get to that point? How can we ensure that the software we write is working as expected and there is no need for a QA person in our team?&lt;/p>
&lt;h2 id="the-hidden-truth-behind-the-lack-of-software-quality">The hidden truth behind the lack of software quality
&lt;a class="heading-anchor" href="#the-hidden-truth-behind-the-lack-of-software-quality" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Unfortunately, in our software industry, the demand for “fast, quick and dirty” projects ended up in poorly developed MVPs by simply applying patches and code over code with just manual testing checking happy paths, sometimes even ignoring edge cases.&lt;/p>
&lt;blockquote>
&lt;p>“The deadline is in one week, so you better finish it on time!”&lt;/p>
&lt;/blockquote>
&lt;p>We don’t learn the importance of what automated testing can bring to our daily job, so we don’t take it seriously, and therefore, we don’t practice it enough. And, for that exact reason, because we don’t practice it, we don’t know how to perform it properly. Yes, I am talking about writing automated tests that prove the behavior of your software!&lt;/p>
&lt;p>Our inability to write testable code results in software that is hard to test, and thus we delegate testing to other third parties shifting the responsibility for the overall end quality of the product or service we write.&lt;/p>
&lt;h2 id="practice-makes-the-master">Practice makes the master
&lt;a class="heading-anchor" href="#practice-makes-the-master" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>You must learn and apply proper testing techniques when they make sense. How and when effectively use test doubles, prepare solitary or sociable tests, which compromises and reasons backup your mind when choosing one or other paths toward your testing strategies?&lt;/p>
&lt;p>You are the latest and main responsible person in charge of your knowledge, so you better invest in yourself because no one else will do it for you.&lt;/p>
&lt;p>Look at everything you do as an opportunity for learning. Practice and get better by default at everything you do.&lt;/p>
&lt;p>If you don’t know how to start, here is my favourite tip: you can always practice and improve your testing skills using code-katas. Read more about this topic &lt;a href="/blog/test-driven-development/">here&lt;/a>.&lt;/p>
&lt;h2 id="nice-theory-but-why-bother">Nice theory, but… why bother?
&lt;a class="heading-anchor" href="#nice-theory-but-why-bother" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Manual testing is, of course, necessary. It is another testing strategy that I am not blaming or attacking. We might still need a dedicated person in charge of discovering what new features we want to build to satisfy our clients. But this blog-post is not about that position.&lt;/p>
&lt;p>It is all about shortening the feedback loop. If you can write software to work in specific ways, can’t you write automated tests to prove that the software you wrote behaves the way you expect?&lt;/p>
&lt;p>If you have covered with automated tests the behavior of your software at any level that makes sense, what’s left for a dedicated QA person?&lt;/p>
&lt;p>Next time you think about “We need a QA person to test this,” try the exercise of thinking instead, “How can I write an automated test that verifies what I would expect if a QA person were checking this?”&lt;/p>
&lt;p>And that’s how you change the “full-time QA position” into a “role mentality for everyone that writes software.”&lt;/p>
&lt;p>Code never lies and never forgets; once it’s written and automated in your pipeline, you can run it anytime at zero cost.&lt;/p>
&lt;p>&lt;img src="/images/blog/2023-05-17/footer.webp" alt="blog-footer" />&lt;/p></content></entry><entry xml:lang="en"><title>Interview About XP and Agile</title><subtitle>Agile is about HOW you do certain things</subtitle><category term="agile" scheme="https://chemaclass.com/tags/agile/" label="Agile"/><category term="xp" scheme="https://chemaclass.com/tags/xp/" label="Xp"/><category term="tdd" scheme="https://chemaclass.com/tags/tdd/" label="Tdd"/><category term="communication" scheme="https://chemaclass.com/tags/communication/" label="Communication"/><published>2023-01-09T00:00:00+00:00</published><updated>2023-01-09T00:00:00+00:00</updated><author><name>
Chemaclass</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/blog/interview-about-xp-and-agile/"/><id>https://chemaclass.com/blog/interview-about-xp-and-agile/</id><summary type="html">My interview with devm.io regarding Agile and Extreme Programming. Agile is more about HOW you do certain things, rather than WHAT things you do.</summary><content type="html">&lt;p>My interview with &lt;strong>devm.io&lt;/strong> regarding Agile and Extreme Programming.&lt;/p>
&lt;span id="continue-reading">&lt;/span>
&lt;hr />
&lt;p>&lt;strong>devm.io: We talked to Chema, a software developer and an Extreme Programming expert, about his favourite topic and his upcoming live event &lt;a rel="external" href="https://devm.io/update-your-team-to-be-more-extreme/">Update Your Team To Be More Extreme&lt;/a>.&lt;/strong>&lt;/p>
&lt;h2 id="could-you-tell-us-a-little-about-yourself-who-you-are-and-what-you-do">Could you tell us a little about yourself, who you are, and what you do?
&lt;a class="heading-anchor" href="#could-you-tell-us-a-little-about-yourself-who-you-are-and-what-you-do" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Chema: My name is Jose Maria Valera Reales, but everyone calls me Chema. I’m originally from Spain but have lived in Berlin since 2015. I’ve been working as a software developer since 2013. In recent years, I have focused on achieving excellence and figuring out how to help my peers and, with them, the entire software community to improve in our profession.&lt;/p>
&lt;p>I am currently a Tech Lead at &lt;a rel="external" href="https://teufel.de/">Lautsprecher Teufel GmbH&lt;/a>, where I work with the e-commerce webshop team. I also enjoy &lt;a rel="external" href="https://github.com/Chemaclass">open-source software&lt;/a>, so I enjoy creating pull requests for other repositories, and I also love when I receive pull requests from others.&lt;/p>
&lt;h2 id="how-would-you-describe-extreme-programming-what-makes-it-so-extreme">How would you describe Extreme Programming? What makes it so “extreme?”
&lt;a class="heading-anchor" href="#how-would-you-describe-extreme-programming-what-makes-it-so-extreme" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Extreme Programming is the most straightforward and pragmatic approach to embracing Agile in your software team. It incorporates solutions based on values, principles, and practices. You don’t have to use or do everything, but rather whatever fits you and your team in your context. However, these are helpful general solutions that work better when combined.&lt;/p>
&lt;p>From my experience, the word “extreme” can be misleading, but I see it as an opportunity to emphasise the difficulty of the fundamentals behind it. The critical point is realising that our “common sense” is not as “common” as we tend to think, nor the best practices for practical teamwork. Therefore, this is about pushing ourselves to extreme effectiveness, collaboration, and satisfaction while working with others.&lt;/p>
&lt;h2 id="you-will-host-a-live-event-on-devm-io-on-the-topic-on-january-19th-could-you-give-us-a-sneak-peek-of-what-your-audience-can-expect">You will host a live event on devm.io on the topic on January 19th. Could you give us a sneak peek of what your audience can expect?
&lt;a class="heading-anchor" href="#you-will-host-a-live-event-on-devm-io-on-the-topic-on-january-19th-could-you-give-us-a-sneak-peek-of-what-your-audience-can-expect" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>We will explore how a software team works nowadays, the common issues we encounter, and what solutions we could apply to improve our team routines. We will look for the real meaning of Agile, focusing on Extreme Programming ideas.&lt;/p>
&lt;p>In addition, I will share some ideas to help your team create learning opportunities with concrete examples that any team can incorporate into their current work.&lt;/p>
&lt;h2 id="during-the-event-you-will-also-tell-us-something-about-katas-what-exactly-are-katas">During the event, you will also tell us something about Katas. What exactly are Katas?
&lt;a class="heading-anchor" href="#during-the-event-you-will-also-tell-us-something-about-katas-what-exactly-are-katas" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>The term “kata” comes from the repetitive movements done in karate that help you improve your fighting skills.&lt;/p>
&lt;p>Why “code katas?” Because as a group, we need to practice more. Most of our learning takes place on the job, so most of our mistakes are also made there. And because we want to keep PROD, we’re reluctant to try new things.&lt;/p>
&lt;p>Katas exist to help developers get the same benefits you would get from practice in any other profession. These simple, simulation exercises let you experiment and learn without the pressure of PROD. There are no right or wrong answers in any software kata: the benefit comes from the process, not the result.&lt;/p>
&lt;p>There are katas to help you improve your refactoring skills (such as Gilded Rose Refactoring Kata by Emily Bache) or your testing skills (easy ones like Fizz Buzz or Roman Numerals, or more advanced ones like the Bank Kata by Sandro Mancuso). They’re also great for building confidence when programming with others, watching and practising different roles collaboratively, fostering team cohesion, etc.&lt;/p>
&lt;h2 id="what-role-do-agile-methods-play-in-software-development-for-you">What role do Agile methods play in software development for you?
&lt;a class="heading-anchor" href="#what-role-do-agile-methods-play-in-software-development-for-you" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>The very first question here is to define what Agile methods are. In the end, everyone communicates somehow, provides feedback to others, and simplifies to some level. Sometimes people have the courage to speak their minds and sometimes they do not, and usually, they try to respect their peers. So, for me, Agile is more about “how” you do certain things rather than “what” things you do.&lt;/p>
&lt;p>Agile is a highly collaborative working process at any level, which might have a challenging learning curve at the beginning, but it pays off sooner than you might expect.&lt;/p>
&lt;h2 id="which-topic-in-the-area-of-agile-should-receive-more-attention">Which topic in the area of agile should receive more attention?
&lt;a class="heading-anchor" href="#which-topic-in-the-area-of-agile-should-receive-more-attention" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Team building and embracing agility, starting with asking “why?” We need to challenge the status quo more often and ask ourselves why we work the way we do and how and what we could do differently to keep improving and never stop learning.&lt;/p>
&lt;blockquote>
&lt;p>You can also read the interview from the original link: &lt;a rel="external" href="https://devm.io/agile/extreme-programming-agile">https://devm.io/agile/extreme-programming-agile&lt;/a>.&lt;/p>
&lt;/blockquote></content></entry><entry xml:lang="en"><title>Clean Craftsmanship</title><subtitle>Disciplines, Standards, and Ethics</subtitle><category term="clean-code" scheme="https://chemaclass.com/tags/clean-code/" label="Clean Code"/><category term="tdd" scheme="https://chemaclass.com/tags/tdd/" label="Tdd"/><category term="refactoring" scheme="https://chemaclass.com/tags/refactoring/" label="Refactoring"/><category term="testing" scheme="https://chemaclass.com/tags/testing/" label="Testing"/><category term="xp" scheme="https://chemaclass.com/tags/xp/" label="Xp"/><published>2022-07-11T00:00:00+00:00</published><updated>2022-07-11T00:00:00+00:00</updated><author><name>
Robert C. Martin</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/readings/clean-craftsmanship/"/><id>https://chemaclass.com/readings/clean-craftsmanship/</id><summary type="html">Robert C. Martin covers the three pillars of software craftsmanship: TDD disciplines with practical examples, professional standards for teams, and the ethical responsibilities of programmers.</summary><content type="html">&lt;span id="continue-reading">&lt;/span>
&lt;p>The book is divided into three parts: the disciplines, the standards, and the ethics.&lt;/p>
&lt;p>The 1st part is the most technical one. It guides you with TDD examples, showing how testing can help you to design your code.&lt;/p>
&lt;p>The 2nd part is about productivity, quality, and courage.&lt;/p>
&lt;p>The 3rd part is about how did we get here in terms of people who develop software, and our responsibility within
our ethics about do no harm, integrity, and teamwork.&lt;/p>
&lt;hr />
&lt;p>One of my favourite parts from the book:&lt;/p>
&lt;blockquote>
&lt;p>Our software industry is wildly dynamic and changing; therefore, we must all be continuously aggressive learners.&lt;/p>
&lt;p>How and when do you do this learning? If your employer provides you the time and space to do this kind of learning, then
take as much advantage of it as you can. If your employer is not helpful, then you’ll have to learn on your own time.&lt;/p>
&lt;p>Be prepared to spend several hours per month on it. Make sure you have the personal time set aside for it.&lt;/p>
&lt;p>Yes, I know you have family obligations, bills to pay, planes to catch, and you’ve got a life. Okay, but you also have a
profession. And professions need care and maintenance. I expect us all to be continuous aggressive learners.&lt;/p>
&lt;p>&lt;code>Chapter 11. Courage - Continuous Aggressive Learning&lt;/code>&lt;/p>
&lt;/blockquote>
&lt;hr />
&lt;h2 id="index">Index
&lt;a class="heading-anchor" href="#index" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;h3 id="part-i-the-disciplines">Part I: The Disciplines
&lt;a class="heading-anchor" href="#part-i-the-disciplines" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;h4 id="chapter-1-craftsmanship">Chapter 1. Craftsmanship
&lt;a class="heading-anchor" href="#chapter-1-craftsmanship" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h4>
&lt;ul>
&lt;li>Extreme Programming&lt;/li>
&lt;li>Test-Driven Development&lt;/li>
&lt;li>Refactoring&lt;/li>
&lt;li>Simple Design&lt;/li>
&lt;li>Collaborative Programming&lt;/li>
&lt;li>Acceptance Tests&lt;/li>
&lt;/ul>
&lt;h4 id="chapter-2-test-driven-development">Chapter 2. Test-Driven Development
&lt;a class="heading-anchor" href="#chapter-2-test-driven-development" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h4>
&lt;ul>
&lt;li>Overview&lt;/li>
&lt;li>The Basics&lt;/li>
&lt;/ul>
&lt;h4 id="chapter-3-advanced-tdd">Chapter 3. Advanced TDD
&lt;a class="heading-anchor" href="#chapter-3-advanced-tdd" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h4>
&lt;ul>
&lt;li>Getting Stuck&lt;/li>
&lt;li>Arrange, Act, Assert&lt;/li>
&lt;li>Test Doubles&lt;/li>
&lt;li>Architecture&lt;/li>
&lt;/ul>
&lt;h4 id="chapter-4-test-design">Chapter 4. Test Design
&lt;a class="heading-anchor" href="#chapter-4-test-design" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h4>
&lt;ul>
&lt;li>Testing Databases&lt;/li>
&lt;li>Testing GUIs&lt;/li>
&lt;li>Test Patterns&lt;/li>
&lt;li>Test-Specific Subclass&lt;/li>
&lt;li>Humble Object&lt;/li>
&lt;li>Test Design&lt;/li>
&lt;li>Breaking the Correspondence&lt;/li>
&lt;/ul>
&lt;h4 id="chapter-5-refactoring">Chapter 5. Refactoring
&lt;a class="heading-anchor" href="#chapter-5-refactoring" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h4>
&lt;ul>
&lt;li>What Is Refactoring?&lt;/li>
&lt;li>The Basic Toolkit&lt;/li>
&lt;li>Extract Method&lt;/li>
&lt;li>The Disciplines&lt;/li>
&lt;/ul>
&lt;h4 id="chapter-6-simple-design">Chapter 6. Simple Design
&lt;a class="heading-anchor" href="#chapter-6-simple-design" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h4>
&lt;ul>
&lt;li>YAGNI&lt;/li>
&lt;li>Covered by Tests&lt;/li>
&lt;li>Coverage&lt;/li>
&lt;li>Design?&lt;/li>
&lt;li>Maximize Expression&lt;/li>
&lt;li>The Underlying Abstraction&lt;/li>
&lt;li>Minimize Duplication&lt;/li>
&lt;li>Minimize Size&lt;/li>
&lt;/ul>
&lt;h4 id="chapter-7-collaborative-programming">Chapter 7. Collaborative Programming
&lt;a class="heading-anchor" href="#chapter-7-collaborative-programming" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h4>
&lt;h4 id="chapter-8-acceptance-tests">Chapter 8. Acceptance Tests
&lt;a class="heading-anchor" href="#chapter-8-acceptance-tests" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h4>
&lt;ul>
&lt;li>The Discipline&lt;/li>
&lt;li>The Continuous Build&lt;/li>
&lt;/ul>
&lt;h3 id="part-ii-the-standards">Part II: The Standards
&lt;a class="heading-anchor" href="#part-ii-the-standards" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;h4 id="chapter-9-productivity">Chapter 9. Productivity
&lt;a class="heading-anchor" href="#chapter-9-productivity" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h4>
&lt;ul>
&lt;li>We Will Never Ship S**T&lt;/li>
&lt;li>Inexpensive Adaptability&lt;/li>
&lt;li>We Will Always Be Ready&lt;/li>
&lt;li>Stable Productivity&lt;/li>
&lt;/ul>
&lt;h4 id="chapter-10-quality">Chapter 10. Quality
&lt;a class="heading-anchor" href="#chapter-10-quality" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h4>
&lt;ul>
&lt;li>Continuous Improvement&lt;/li>
&lt;li>Fearless Competence&lt;/li>
&lt;li>Extreme Quality&lt;/li>
&lt;li>We Will Not Dump on QA&lt;/li>
&lt;li>QA Will Find Nothing&lt;/li>
&lt;li>Test Automation&lt;/li>
&lt;li>Automated Testing and User Interfaces&lt;/li>
&lt;li>Testing the User Interface&lt;/li>
&lt;/ul>
&lt;h4 id="chapter-11-courage">Chapter 11. Courage
&lt;a class="heading-anchor" href="#chapter-11-courage" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h4>
&lt;ul>
&lt;li>We Cover for Each Other&lt;/li>
&lt;li>Honest Estimates&lt;/li>
&lt;li>You Must Say NO&lt;/li>
&lt;li>Continuous Aggressive Learning&lt;/li>
&lt;li>Mentoring&lt;/li>
&lt;/ul>
&lt;h3 id="part-iii-the-ethics">Part III: The Ethics
&lt;a class="heading-anchor" href="#part-iii-the-ethics" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>The First Programmer&lt;/li>
&lt;li>Seventy-Five Years&lt;/li>
&lt;li>Nerds and Saviors&lt;/li>
&lt;li>Role Models and Villains&lt;/li>
&lt;li>We Rule the World&lt;/li>
&lt;li>Catastrophes&lt;/li>
&lt;li>The Oath&lt;/li>
&lt;/ul>
&lt;h4 id="chapter-12-harm">Chapter 12. Harm
&lt;a class="heading-anchor" href="#chapter-12-harm" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h4>
&lt;ul>
&lt;li>First, Do No Harm&lt;/li>
&lt;li>Best Work&lt;/li>
&lt;li>Repeatable Proof&lt;/li>
&lt;/ul>
&lt;h4 id="chapter-13-integrity">Chapter 13. Integrity
&lt;a class="heading-anchor" href="#chapter-13-integrity" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h4>
&lt;ul>
&lt;li>Small Cycles&lt;/li>
&lt;li>Relentless Improvement&lt;/li>
&lt;li>Maintain High Productivity&lt;/li>
&lt;/ul>
&lt;h4 id="chapter-14-teamwork">Chapter 14. Teamwork
&lt;a class="heading-anchor" href="#chapter-14-teamwork" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h4>
&lt;ul>
&lt;li>Work as a Team&lt;/li>
&lt;li>Estimate Honestly and Fairly&lt;/li>
&lt;li>Respect&lt;/li>
&lt;li>Never Stop Learning&lt;/li>
&lt;/ul>
&lt;hr />
&lt;p>I found this chat in YouTube where Uncle Bob talks about most of the topics form his book &lt;strong>Clean Craftsmanship&lt;/strong>.&lt;/p>
&lt;div style="position:relative;aspect-ratio:16/9;width:100%;">
&lt;iframe
src="https://www.youtube-nocookie.com/embed/sPXk11hrWTM"
title="YouTube video"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
referrerpolicy="strict-origin-when-cross-origin"
style="position:absolute;inset:0;width:100%;height:100%;border:0;"
allowfullscreen>
&lt;/iframe>
&lt;/div>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="plain">&lt;span class="giallo-l">&lt;span>Listen out for:&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>* Quote &amp;amp; Intro - [00:00:00]&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>* Career Journey - [00:07:29]&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>* Clean Craftsmanship - [00:10:53]&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>* Programmer as a Profession - [00:15:31]&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>* Craftsmanship - [00:18:45]&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>* Disciplines - [00:22:45]&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>* Disciplines: Test-Driven Development - [00:28:49]&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>* Disciplines: Refactoring - [00:34:31]&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>* Code Coverage - [00:39:02]&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>* Standard: Never Ship S**t - [00:42:35]&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>* Standard: Always Be Ready - [00:47:15]&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>* Ethics: Do No Harm - [00:50:00]&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>* Ethics: Estimate Honestly - [00:53:56]&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>* 2 Tech Lead Wisdom - [00:57:50]&lt;/span>&lt;/span>&lt;/code>&lt;/pre></content></entry><entry xml:lang="en"><title>The Path to Seniority in Software</title><subtitle>How to become a Senior Software Developer?</subtitle><category term="career" scheme="https://chemaclass.com/tags/career/" label="Career"/><category term="mentoring" scheme="https://chemaclass.com/tags/mentoring/" label="Mentoring"/><category term="clean-code" scheme="https://chemaclass.com/tags/clean-code/" label="Clean Code"/><category term="tdd" scheme="https://chemaclass.com/tags/tdd/" label="Tdd"/><category term="communication" scheme="https://chemaclass.com/tags/communication/" label="Communication"/><published>2022-06-08T00:00:00+00:00</published><updated>2022-06-08T00:00:00+00:00</updated><author><name>
Chemaclass</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/blog/the-path-to-seniority-in-software/"/><id>https://chemaclass.com/blog/the-path-to-seniority-in-software/</id><summary type="html">Real seniority goes beyond job titles. It's about impact, mentoring others, owning outcomes, and raising the bar for your entire team.</summary><content type="html">&lt;p>We all have been junior developers at some point. This is easy to know because it sits at the very beginning of your
career. Your responsibilities were narrowed down by other peers who were looking after you.&lt;/p>
&lt;span id="continue-reading">&lt;/span>
&lt;p>At some point, after months or years, you got your promotion or another job, where you weren’t a junior
anymore, but an intermediate.&lt;/p>
&lt;p>An intermediate (also known as middle) is something between junior and senior. You know now that you are not a junior
anymore, you know how to deliver value but yet you also have mixed feelings about seniority. You want to be a senior,
but you don’t know how. There is no clear path to achieving this goal.&lt;/p>
&lt;p>Wait for a second… there are actually two easy ways to get the senior title! You can get promoted as such in your
company, or you can start a new position as a “senior” in another company, easy right?&lt;/p>
&lt;h2 id="marketing-and-politics">Marketing and politics
&lt;a class="heading-anchor" href="#marketing-and-politics" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Unfortunately, the “seniority” level is very much polluted by marketing and politics. First, what
does it mean “senior” in this context? In all the companies where I have been working (if not all) I have always been
surrounded by people who claimed to be “seniors” when in reality only a few I would consider such.&lt;/p>
&lt;p>Our senior label is inflated by companies needing experts on paper more than in reality, and this is a
problem we need to deal with and speak about.&lt;/p>
&lt;p>Seniority generally means more experience, but how do you calculate this? It is easy from a company’s point of view:
more years in the industry. But, is the number of years you have been working really relevant in an industry that is
constantly changing and evolving? Actually, this wouldn’t be a big issue if you have the software fundamentals
well interiorized, but funny enough, I have seen these fundamentals in only ~10% of the seniors I have met across many
years and several companies.&lt;/p>
&lt;p>The fact that you have been working for 10 or more years doesn’t necessarily mean you are a “senior” with software.
What else can we measure in order to identify if you deserve indeed this title?&lt;/p>
&lt;h3 id="it-is-not-all-about-the-money">It is not all about the money
&lt;a class="heading-anchor" href="#it-is-not-all-about-the-money" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Let us be honest, senior titles are better paid than junior or middle positions. If you have the chance to get a higher
salary because you got the “senior” in your job title, well, it wouldn’t be clever to reject it. But, independently of
politics and marketing, we must address some seniority fundamentals to understand better what the word “senior” means in
this context.&lt;/p>
&lt;blockquote>
&lt;p>It is not all about the money, but also about the responsibilities that come with seniority.&lt;/p>
&lt;/blockquote>
&lt;h2 id="seniority-fundamentals">Seniority fundamentals
&lt;a class="heading-anchor" href="#seniority-fundamentals" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Being senior in our software industry is not about “the number of years of experience” but:&lt;/p>
&lt;ul>
&lt;li>How well do you &lt;strong>transmit your knowledge&lt;/strong> to others? Sharing what you know is a core task for a senior person.&lt;/li>
&lt;li>How well do you &lt;strong>collaborate&lt;/strong> with other people, including the PM/PO and other teams? Collaboration is crucial
to creating a constant feedback loop.&lt;/li>
&lt;li>How well do you &lt;strong>work together&lt;/strong> with your peers? Pair-programming builds team cohesion and helps everyone become
better.&lt;/li>
&lt;li>How strong are your &lt;strong>testing&lt;/strong> skills? Testing is tied to the quality of your work, and a senior should aim
for an incremental design.&lt;/li>
&lt;li>How well do you understand &lt;strong>delivering value constantly&lt;/strong> in small chunks? The sooner you deliver value, the
sooner you get feedback about it.&lt;/li>
&lt;li>How deep is your &lt;strong>technical knowledge&lt;/strong> of quality software and the trade-offs to get there?
SOLID principles, clean code, TDD, refactoring as part of your daily job, low coupling, high cohesion, appropriate
data structures, and choosing the right solution (KISS, YAGNI…).&lt;/li>
&lt;li>How well do you adapt and &lt;strong>cope with change&lt;/strong>? Change is inevitable, so we must learn to
deal with it, especially the parts we cannot control.&lt;/li>
&lt;li>How developed is your &lt;strong>entrepreneurial thinking&lt;/strong>? Always keeping the organization’s goals in mind.&lt;/li>
&lt;/ul>
&lt;p>As you can see, there is no mention of concrete technology or years of experience. Why? Because technology is just an
“implementation detail”, and experience comes by practicing and attitude, not by letting the time pass by.&lt;/p>
&lt;h3 id="attitude-is-important">Attitude is important
&lt;a class="heading-anchor" href="#attitude-is-important" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>We’ve got two persons:&lt;/p>
&lt;p>A) a person who is working for 15 years, doing relatively the same every day, and without caring about his own skills.
He just does what others tell him to do.&lt;/p>
&lt;p>B) a person who is working for 5 years, challenging herself every week, trying different approaches when dealing with
problems, and sharpening her own skills constantly.&lt;/p>
&lt;p>Can you see the main difference? No, it’s not the 10 years difference of “experience” between them, but their &lt;strong>attitude&lt;/strong>.&lt;/p>
&lt;p>We wrongly understand that &lt;em>a year of experience must come with learning and knowledge&lt;/em>, so we tend to use time as a
measurement of seniority. But I argue that the “attitude factor” is equal or even more important. I have been surrounded
by many people who call themselves seniors with 3, 6, 10, and more years of “experience” but lacking attitude, and you
could clearly see this problem on a daily basis.&lt;/p>
&lt;blockquote>
&lt;p>You need this combination to build yourself as a truly senior developer; time, experience, and most importantly:
attitude towards &lt;strong>improving your own skills and the ones that surround you&lt;/strong>.&lt;/p>
&lt;/blockquote>
&lt;h2 id="where-to-start">Where to start
&lt;a class="heading-anchor" href="#where-to-start" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Seniority is not granted, it is practiced. You don’t wait for the title, you build the behavior until the title catches
up. Start small, and start now:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Teach what you know.&lt;/strong> Pick one thing you understand and explain it to someone this week. If you can’t explain it,
you don’t own it yet.&lt;/li>
&lt;li>&lt;strong>Seek the uncomfortable.&lt;/strong> Volunteer for the task slightly beyond you. Growth lives at the edge of what you can
already do.&lt;/li>
&lt;li>&lt;strong>Reflect on purpose.&lt;/strong> After each project, ask what you would do differently. Experience without reflection is just
repetition.&lt;/li>
&lt;/ul>
&lt;p>The path is not a promotion. It is the daily decision to improve yourself and the people around you. Do that long
enough, and the title becomes a formality.&lt;/p></content></entry><entry xml:lang="en"><title>Update Your Team to Be More Extreme</title><subtitle>How can you help your peers to embrace the change?</subtitle><category term="xp" scheme="https://chemaclass.com/tags/xp/" label="Xp"/><category term="agile" scheme="https://chemaclass.com/tags/agile/" label="Agile"/><category term="team-management" scheme="https://chemaclass.com/tags/team-management/" label="Team Management"/><category term="mentoring" scheme="https://chemaclass.com/tags/mentoring/" label="Mentoring"/><category term="tdd" scheme="https://chemaclass.com/tags/tdd/" label="Tdd"/><published>2022-02-26T00:00:00+00:00</published><updated>2023-03-23T00:00:00+00:00</updated><author><name>
Chemaclass</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/blog/update-your-team-to-be-more-extreme/"/><id>https://chemaclass.com/blog/update-your-team-to-be-more-extreme/</id><summary type="html">Our profession is constantly evolving; therefore, it demands a non-stop learning process. Embracing the change is not optional in our software industry. We need to create spaces to get out of our comfort zone.</summary><content type="html">&lt;p>Our software profession is constantly evolving; it demands a non-stop learning process. We must embrace the change in our industry.&lt;/p>
&lt;span id="continue-reading">&lt;/span>
&lt;p>We need to create spaces to get out of our comfort zone, so our cognitive brain can train and improve how to adapt to our surroundings, which are constantly transforming.&lt;/p>
&lt;h2 id="why-code-katas-tech-talks-or-research-fridays">Why code katas, tech talks or research Fridays?
&lt;a class="heading-anchor" href="#why-code-katas-tech-talks-or-research-fridays" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>The goal is to help create an environment that aims for continuous improvement towards looking for learning everywhere, all the time, as the core attitude for the individuals and the group.&lt;/p>
&lt;h3 id="create-learnings-opportunities">Create learnings opportunities
&lt;a class="heading-anchor" href="#create-learnings-opportunities" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;blockquote>
&lt;p>Schedule some time every X weeks for practicing together.&lt;/p>
&lt;/blockquote>
&lt;p>At the end of each iteration, or even 2 or 4 weeks, we celebrate and work on katas in pairs/mob for 2 hours. That space is also an opportunity to create an internal tech-talk presentation to share exciting knowledge with the team non-directly-related to our “regular daily business”.&lt;/p>
&lt;p>The goal is to get out of our comfort zone, improving our recognition for change in general while learning other subjects regularly.&lt;/p>
&lt;h2 id="what-is-a-code-kata">What is a code kata?
&lt;a class="heading-anchor" href="#what-is-a-code-kata" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>As a group, software developers don’t practice enough. Most of our learning takes place on the job, so most of our mistakes get made there as well.&lt;/p>
&lt;p>The term “kata” comes from the repetitive movements done in karate that help you improve your fighting skills.&lt;/p>
&lt;p>Code Katas exists to help developers get the same benefits as practicing in any other profession. There are simple, artificial exercises that let you experiment and learn without the pressure in a production environment.&lt;/p>
&lt;blockquote>
&lt;p>There are no right or wrong answers in any software kata: the benefit comes from the process, not the result.&lt;/p>
&lt;/blockquote>
&lt;h3 id="motivation">Motivation
&lt;a class="heading-anchor" href="#motivation" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>Work on refactoring techniques.&lt;/li>
&lt;li>Work on TDD examples.&lt;/li>
&lt;li>Work on SOLID principles.&lt;/li>
&lt;li>Work on live coding sessions.&lt;/li>
&lt;li>Work on driver-navigator concepts.&lt;/li>
&lt;li>Work on team cohesion.&lt;/li>
&lt;li>Have fun while learning and practicing together.&lt;/li>
&lt;/ul>
&lt;p>If you’re interested in my thoughts about TDD and katas, I wrote a post about it not long ago:
&lt;a href="/blog/test-driven-development/">Test-Driven Development&lt;/a>.&lt;/p>
&lt;h2 id="what-is-a-tech-talk">What is a tech-talk?
&lt;a class="heading-anchor" href="#what-is-a-tech-talk" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Tech talks allow us to share some knowledge related to our tech industry with our team members.&lt;/p>
&lt;p>It can be any FrontEnd, BackEnd, DevOps related. But I encourage also:&lt;/p>
&lt;ul>
&lt;li>a new programming language that you are learning,&lt;/li>
&lt;li>a summary of one book that you finished,&lt;/li>
&lt;li>a new technology that you are studying or feeling curious about,&lt;/li>
&lt;li>a piece of software that you would like to share and present thoughts about it,&lt;/li>
&lt;li>a new tool that helps you to improve your productivity,&lt;/li>
&lt;li>really: &lt;u>anything related to creating value or knowledge.&lt;/u>&lt;/li>
&lt;/ul>
&lt;h3 id="how-can-i-present-a-tech-talk">How can I present a tech talk?
&lt;a class="heading-anchor" href="#how-can-i-present-a-tech-talk" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>I wrote this article with some tips about &lt;a href="/blog/improve-your-tech-talk/">how to improve your tech-talk&lt;/a>. Some key
questions that might help you to find something on your own:&lt;/p>
&lt;ul>
&lt;li>What have you learned recently (in the last X months)?&lt;/li>
&lt;li>What knowledge might be interesting to be shared with your peers?&lt;/li>
&lt;li>Which aspect of yourself you’d like to improve professionally and/or personally?&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>Just one rule: Be curious and “&lt;a href="/blog/embrace-the-change/">embrace the change&lt;/a>.”&lt;/p>
&lt;/blockquote>
&lt;h2 id="research-and-learning-fridays">Research and learning Fridays
&lt;a class="heading-anchor" href="#research-and-learning-fridays" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Block the last Friday of the month for research and learning purposes.
The whole team will have a dedicated space for growth and experiment.&lt;/p>
&lt;p>It’s crucial to build trust with your team, so you all know everyone will use this time as good as possible. Don’t micromanage this time forcing keeping a record in a wikipage with what everyone does in detail.&lt;/p>
&lt;p>Although, it would be nice that the team shares what they do during this time, mostly to create transparency among themselves. A verbal announcement to the peers the day before, with their intentions. Even the day after with the learnings key-takeaways.&lt;/p>
&lt;h3 id="summary">Summary
&lt;a class="heading-anchor" href="#summary" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>You can help your team to be more extreme by helping with a dedicated team space for growth and experimentation.&lt;/p>
&lt;ul>
&lt;li>Provide flexibility to experiment with these ideas as they see fit.&lt;/li>
&lt;li>It is an opportunity for self-growth and learning at the same time.&lt;/li>
&lt;li>It is, ultimately, up to the person and the team.&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>Do not micromanage this dedicated time. Focus on the outcome. Help your team to grow, and they will enjoy growing with you.&lt;/p>
&lt;/blockquote>
&lt;p>&lt;img src="/images/blog/2022-02-26/footer.webp" alt="blog-footer" />&lt;/p>
&lt;h2 id="tech-talk">Tech Talk
&lt;a class="heading-anchor" href="#tech-talk" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>After writing this blog post (originally in Feb, 2022), I was invited to do
a &lt;a href="/talks/update-your-team-to-be-more-extreme">tech talk&lt;/a> in different conferences about this topic.&lt;/p></content></entry><entry xml:lang="en"><title>London vs Chicago</title><subtitle>It's an integration, not a choice</subtitle><category term="tdd" scheme="https://chemaclass.com/tags/tdd/" label="Tdd"/><category term="testing" scheme="https://chemaclass.com/tags/testing/" label="Testing"/><category term="software-design" scheme="https://chemaclass.com/tags/software-design/" label="Software Design"/><category term="refactoring" scheme="https://chemaclass.com/tags/refactoring/" label="Refactoring"/><published>2021-11-20T00:00:00+00:00</published><updated>2021-11-20T00:00:00+00:00</updated><author><name>
Chemaclass</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/blog/london-vs-chicago/"/><id>https://chemaclass.com/blog/london-vs-chicago/</id><summary type="html">There are two known schools in TDD: the mockist school (aka Outside-in) and the classicist school (aka Inside-out).</summary><content type="html">&lt;p>There are two known schools in TDD: the mockist school (aka Outside-in) and the classicist school (aka Inside-out).&lt;/p>
&lt;span id="continue-reading">&lt;/span>&lt;h3 id="why-london-and-chicago">Why London and Chicago?
&lt;a class="heading-anchor" href="#why-london-and-chicago" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Two companies, one from London and another from Chicago, claimed to do TDD, but they were focused on different aspects.
The London company was building software from outside-in, while the Chicago company from inside-out. Let’s see them in more detail.&lt;/p>
&lt;h2 id="outside-in-london-school">Outside-in: London School
&lt;a class="heading-anchor" href="#outside-in-london-school" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>It provides a behavior-driven approach to TDD. Starting from the outside of the application and working inwards to
lower layers. For example, starting from the API/Controllers down to the application or domain layers.&lt;/p>
&lt;h3 id="pros">PROS
&lt;a class="heading-anchor" href="#pros" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>Behavioral Focused&lt;/strong>: this requires a lot of test doubles because you will test a lot of abstractions that don’t exist
yet as you are creating a high level of logic first. You aren’t going to write dead-code but it will be easy to create
tests highly coupled to the logic and therefore making refactoring a difficult task.&lt;/li>
&lt;li>&lt;strong>Command-Query separation&lt;/strong>: is a discipline for managing side effects. Either you perform an action (command) or you ask
for a value (query).&lt;/li>
&lt;/ul>
&lt;h3 id="cons">CONS
&lt;a class="heading-anchor" href="#cons" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>Fragile Tests&lt;/strong>: it tends to create tests that break easily because they are usually too coupled to the production code.&lt;/li>
&lt;li>&lt;strong>Difficult Refactoring&lt;/strong>: for the same reason as “Fragile Tests”, having tests coupled to production code make continuous
refactoring very difficult and time-consuming.&lt;/li>
&lt;/ul>
&lt;h2 id="inside-out-chicago-school">Inside-out: Chicago School
&lt;a class="heading-anchor" href="#inside-out-chicago-school" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>It’s an informal, exploratory, state-based approach of TDD. Starting from the inside of the application (usually the
domain) and working out towards the APIs.&lt;/p>
&lt;h3 id="pros-1">PROS
&lt;a class="heading-anchor" href="#pros-1" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>Strong Safety Net&lt;/strong>: it tends to produce tests that are decoupled from the implementation. Enabling you to adopt a more
experimental style of changing software without fear of breaking it. This is desired for continuous refactoring.&lt;/li>
&lt;li>&lt;strong>High Cohesion&lt;/strong>: as tests become more general, the production code becomes more specific. This promotes high cohesion,
and with high cohesion comes loose coupling. Something that promotes high code quality: extensibility,
maintainability, and testability.&lt;/li>
&lt;li>&lt;strong>Minimizes Test Doubles&lt;/strong>: building from the inside out requires fewer test doubles since you are building on top of the
previously written tests. This helps to develop less fragile tests.&lt;/li>
&lt;/ul>
&lt;h3 id="cons-1">CONS
&lt;a class="heading-anchor" href="#cons-1" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>YAGNI&lt;/strong>: it’s often over-engineering solutions, with code that is not really needed (or even used!) in the end.&lt;/li>
&lt;/ul>
&lt;h2 id="london-and-chicago-work-better-together">London and Chicago work better together
&lt;a class="heading-anchor" href="#london-and-chicago-work-better-together" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>It’s not about choosing one over the other. It’s about understanding your context and driving optimization towards those
qualities that need to be optimized. London and Chicago each have their pros and cons. The best approach to TDD is an
integrated adoption of these two schools.&lt;/p>
&lt;div style="position:relative;aspect-ratio:16/9;width:100%;">
&lt;iframe
src="https://www.youtube-nocookie.com/embed/rbSDGr-_UwY"
title="YouTube video"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
referrerpolicy="strict-origin-when-cross-origin"
style="position:absolute;inset:0;width:100%;height:100%;border:0;"
allowfullscreen>
&lt;/iframe>
&lt;/div>
&lt;hr />
&lt;h3 id="references">References
&lt;a class="heading-anchor" href="#references" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>&lt;a href="/blog/test-driven-development/">Test-Driven (Development)&lt;/a>&lt;/li>
&lt;li>&lt;a href="/blog/tdd-vs-bdd/">TDD vs BDD&lt;/a>&lt;/li>
&lt;li>&lt;a rel="external" href="https://gist.github.com/xpepper/2e3519d2cb8568a0b13739d9ae497f21">Notes about “London vs Chicago TDD styles”&lt;/a>&lt;/li>
&lt;/ul></content></entry><entry xml:lang="en"><title>TDD vs BDD</title><subtitle>Design or Workflow?</subtitle><category term="tdd" scheme="https://chemaclass.com/tags/tdd/" label="Tdd"/><category term="testing" scheme="https://chemaclass.com/tags/testing/" label="Testing"/><category term="software-design" scheme="https://chemaclass.com/tags/software-design/" label="Software Design"/><published>2021-09-25T00:00:00+00:00</published><updated>2021-09-25T00:00:00+00:00</updated><author><name>
Chemaclass</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/blog/tdd-vs-bdd/"/><id>https://chemaclass.com/blog/tdd-vs-bdd/</id><summary type="html">These are two different techniques. The key to each of them is about the mindset and context of what you want to achieve.</summary><content type="html">&lt;p>These are two different techniques. The key to each of them is about the mindset and context of what you want to achieve.&lt;/p>
&lt;span id="continue-reading">&lt;/span>&lt;h2 id="bdd-is-a-test-driven-feature">BDD is a “test-driven feature”
&lt;a class="heading-anchor" href="#bdd-is-a-test-driven-feature" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Basically, it’s a test-first driven development, where the main focus is ensuring the expected final behavior, and
therefore the result of the software logic that you want to have at the end.&lt;/p>
&lt;p>In BDD the main focus is the behavior of your domain logic that doesn’t exist yet. It is, from an abstract point of
view, about the whole functionality and domain requirements.&lt;/p>
&lt;h2 id="tdd-is-about-the-rhythm">TDD is about the rhythm
&lt;a class="heading-anchor" href="#tdd-is-about-the-rhythm" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;ol>
&lt;li>Specify what you want.&lt;/li>
&lt;li>Make it work.&lt;/li>
&lt;li>Make it better.&lt;/li>
&lt;/ol>
&lt;p>TDD is not just about the already known “red-green-refactor” mentality, but mostly about the workflow that helps you
understand the constant design decisions you are doing every time for every logic you are designing.&lt;/p>
&lt;blockquote>
&lt;p>TDD is about constant feedback about your decisions.&lt;/p>
&lt;/blockquote>
&lt;p>In the context of OOP (to make the examples clearer), there are always tons of different ways to design your class:&lt;/p>
&lt;ul>
&lt;li>What’s the name of this method’s class?&lt;/li>
&lt;li>What are the dependencies or collaborators for this class?&lt;/li>
&lt;li>How will this class behave when I use this other class inside it?&lt;/li>
&lt;li>What’s the expected outcome of this method when I give these arguments?&lt;/li>
&lt;li>etc, etc…&lt;/li>
&lt;/ul>
&lt;p>We ask these questions (and many more) every time, and we do give them an answer as well, but usually without any
rational thinking or feedback about it. We just do what we think is “the best” at that particular time focusing on
making something work, but is it enough to make it work?&lt;/p>
&lt;h2 id="the-constant-feedback-loop">The constant feedback loop
&lt;a class="heading-anchor" href="#the-constant-feedback-loop" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Testing is not just a great tool because it gives you some safety-net so you can refactor with confidence, but also
because it helps design a better system. &lt;strong>How is that?&lt;/strong> Because before going for any solution, it makes you think about
the decisions that you need to do. You are challenging yourself to understand the arguments of your decisions, and why A
and not B is a better solution in a particular context.&lt;/p>
&lt;p>BDD and TDD aren’t mutually exclusive, in fact, they can and should coexist. It depends mostly on the context of what
you want to build and test.&lt;/p>
&lt;p>&lt;img src="/images/blog/2021-09-25/bdd-and-tdd.webp" alt="blog-bdd-and-tdd" />&lt;/p>
&lt;p>BDD is about Test-First feature development. The goal is not how but what. The feedback loop is long because you will
get “green” feedback once the feature is implemented and working as expected.&lt;/p>
&lt;p>TDD is also another Test-First driven but, unlike BDD, it is about a shorter and quicker feedback loop.&lt;/p>
&lt;ol>
&lt;li>First, you &lt;strong>specify what you want&lt;/strong>. You think about the design of your class or method. Its name or signature. Its
dependencies. But all of this by baby steps, one at a time.&lt;/li>
&lt;li>Second, you &lt;strong>make that little thing work&lt;/strong> in the simplest possible way.&lt;/li>
&lt;li>Finally, you &lt;strong>make it better&lt;/strong>. Because software is hard and complicated enough to make it right on the first try, so
refactoring is a must to keep a system healthy. At this point, with a “green running test”, you can refactor and
improve your logic safely.&lt;/li>
&lt;/ol>
&lt;p>The above is basically TDD, right, but… what’s so special about it? The constant &lt;strong>feedback loop&lt;/strong> and &lt;strong>design
decisions&lt;/strong> that you need to make before you are actually writing the solution. This is the power of TDD.&lt;/p>
&lt;h3 id="why-so-small-steps-in-tdd">Why so small steps in TDD?
&lt;a class="heading-anchor" href="#why-so-small-steps-in-tdd" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Theoretically you “must” write little steps for every iteration, but why? &lt;strong>It’s all about the feedback loop&lt;/strong>. This is
up to you, your expectations, and your experience with testing.&lt;/p>
&lt;p>&lt;img src="/images/blog/2021-09-25/footer.jpg" alt="small steps in the tdd feedback loop" />&lt;/p>
&lt;hr />
&lt;h3 id="resources">Resources
&lt;a class="heading-anchor" href="#resources" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>&lt;a rel="external" href="https://chemaclass.com/blog/test-driven-development/">https://chemaclass.com/blog/test-driven-development/&lt;/a>&lt;/li>
&lt;li>&lt;a rel="external" href="https://blog.testlodge.com/tdd-vs-bdd/">https://blog.testlodge.com/tdd-vs-bdd/&lt;/a>&lt;/li>
&lt;/ul></content></entry><entry xml:lang="en"><title>Test-Driven (Development)</title><subtitle>What is challenging about it?</subtitle><category term="tdd" scheme="https://chemaclass.com/tags/tdd/" label="Tdd"/><category term="testing" scheme="https://chemaclass.com/tags/testing/" label="Testing"/><category term="software-design" scheme="https://chemaclass.com/tags/software-design/" label="Software Design"/><category term="refactoring" scheme="https://chemaclass.com/tags/refactoring/" label="Refactoring"/><published>2021-08-01T00:00:00+00:00</published><updated>2021-08-01T00:00:00+00:00</updated><author><name>
Chemaclass</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/blog/test-driven-development/"/><id>https://chemaclass.com/blog/test-driven-development/</id><summary type="html">TDD is a design practice, not just a testing technique. Writing tests first changes how you think about code and shape its structure.</summary><content type="html">&lt;p>The complexity here is not about writing tests itself, but the habits that we have to change to create software that is
easy to be tested.&lt;/p>
&lt;span id="continue-reading">&lt;/span>&lt;h2 id="the-root-of-the-problem">The root of the problem
&lt;a class="heading-anchor" href="#the-root-of-the-problem" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Without (a solid) experience in testing, developers can have a hard time while trying to apply testing in general as
part of their daily job. It’s not simply because of the topic’s complexity, but &lt;strong>because they are used to writing
code that is hard to test.&lt;/strong>&lt;/p>
&lt;p>Writing tests for already working software (mainly when it was done without considering testing at all) translates as
something boring, next to useless, usually accompanied by a lack of motivation, blaming the wrong subject in this
context: “the tests itself are reducing my speed”.&lt;/p>
&lt;blockquote>
&lt;p>In a domain context, if a piece of software logic is hard to be tested, the problem is not the test, but the code which wasn’t well written.&lt;/p>
&lt;/blockquote>
&lt;p>There are already hundreds of tutorials, books, and documentation about testing, but I can share my experience and how I
do apply this great (and mandatory) philosophy in my daily work.&lt;/p>
&lt;h3 id="test-driven-is-based-on-this-simple-rule">Test-Driven is based on this simple rule
&lt;a class="heading-anchor" href="#test-driven-is-based-on-this-simple-rule" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>Instead of: design code -&amp;gt; develop code -&amp;gt; write tests.&lt;/li>
&lt;/ul>
&lt;p>&lt;img src="/images/blog/2021-08-01/non-tdd-style.png" alt="non-tdd-style" />&lt;/p>
&lt;ul>
&lt;li>It’s about: write failing automated test -&amp;gt; run failing test -&amp;gt; develop code to make test pass -&amp;gt; run test -&amp;gt; repeat.&lt;/li>
&lt;/ul>
&lt;p>&lt;img src="/images/blog/2021-08-01/tdd-style.png" alt="tdd-style" />&lt;/p>
&lt;p>The idea of driving your code by testing can be understood depending on the abstraction level of what you’re writing at
the moment. You don’t want to create a wrong coupling between the tests and the code being tested. You want to test the
behavior of your logic.&lt;/p>
&lt;p>TDD is based on a loop of baby steps that helps you find &lt;strong>patterns&lt;/strong> and guide your software design every little iteration
with &lt;strong>constant refactorings&lt;/strong>. It’s the best choice if you want to ensure the expected behavior of all possible paths of
your logic.&lt;/p>
&lt;p>The beauty of this is that you don’t need to know the full algorithm from the very beginning. Instead, you are
&lt;strong>discovering&lt;/strong> how your logic should be by expressing the desired implementation, step by step, on automated tests.&lt;/p>
&lt;p>Considering writing tests for your software at the same time you’re writing it, will &lt;strong>irremediably force you to write
better software&lt;/strong>. Because you want to write software which has to be easy to be tested, and therefore it will end up with
higher quality.&lt;/p>
&lt;blockquote>
&lt;p>I already wrote another post about the relation between software &lt;strong>quality and testing&lt;/strong>: &lt;a href="/blog/the-art-of-testing/">The Art of Testing: where design meets quality&lt;/a>.&lt;/p>
&lt;/blockquote>
&lt;h2 id="improve-your-test-driven-skills">Improve your Test-Driven skills
&lt;a class="heading-anchor" href="#improve-your-test-driven-skills" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>&lt;img src="/images/blog/2021-08-01/tdd-style-with-git.png" alt="tdd-style" />&lt;/p>
&lt;p>The best way to learn Test-Driven is doing software katas. Try them alone and with others. Both are equally important.&lt;/p>
&lt;ul>
&lt;li>Alone: to challenge your inner self without any distraction but yourself.&lt;/li>
&lt;li>With others: pair-programming is essential in our job. Katas are the best tools to train our communication skills and
learn together from each other.&lt;/li>
&lt;/ul>
&lt;h3 id="what-s-a-code-kata">What’s a Code Kata?
&lt;a class="heading-anchor" href="#what-s-a-code-kata" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Software developers don’t practice enough. Most of our learning takes place on the job, which means that most of our
mistakes get made there as well.&lt;/p>
&lt;p>Other creative professions practice: musicians play technical pieces, poets constantly rewrite works. In karate, most of
a student’s time is spent learning and refining basic moves. These are katas.&lt;/p>
&lt;h3 id="what-is-the-goal-of-a-kata-what-should-we-have-at-the-end">What is the goal of a kata? What should we have at the end?
&lt;a class="heading-anchor" href="#what-is-the-goal-of-a-kata-what-should-we-have-at-the-end" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Katas exist to help developers get the same benefits as practicing in any other profession. There are simple, artificial
exercises that let you experiment and learn without the pressure of a production environment.&lt;/p>
&lt;blockquote>
&lt;p>There are no right or wrong answers in any software kata: the benefit comes from the process, not from the result.&lt;/p>
&lt;/blockquote>
&lt;h3 id="tips">Tips
&lt;a class="heading-anchor" href="#tips" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>Once you have resolved a kata, try it again in a few weeks or months.&lt;/li>
&lt;li>Try to explore new solutions. Be creative in the process and do not rush.&lt;/li>
&lt;li>When doing them in groups, they are not a competition to see who will accomplish more of the exercise.&lt;/li>
&lt;li>The focus should be on the process, never on the result.&lt;/li>
&lt;li>The true valuable outcome of any kata is the learnings that you (and your team) will get after talking about it and
sharing your experiences.&lt;/li>
&lt;/ul>
&lt;p>You can find a lot of katas on the Internet. For example:&lt;/p>
&lt;ul>
&lt;li>&lt;a rel="external" href="http://codekata.com">http://codekata.com&lt;/a>&lt;/li>
&lt;li>&lt;a rel="external" href="https://codingdojo.org/kata">https://codingdojo.org/kata&lt;/a>&lt;/li>
&lt;li>&lt;a rel="external" href="https://github.com/gamontal/awesome-katas">https://github.com/gamontal/awesome-katas&lt;/a>&lt;/li>
&lt;/ul>
&lt;hr />
&lt;h3 id="tdd-is-more-as-a-workflow-than-a-design">TDD is more as a workflow than a design
&lt;a class="heading-anchor" href="#tdd-is-more-as-a-workflow-than-a-design" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;blockquote>
&lt;p>“TDD is a design tool.” That’s what Sandro has said for years. But not anymore. After working with different teams and in different organisations, and also carefully inspecting how he works, Sandro changed his mind about the role of TDD in software design.&lt;/p>
&lt;/blockquote>
&lt;div style="position:relative;aspect-ratio:16/9;width:100%;">
&lt;iframe
src="https://www.youtube-nocookie.com/embed/KyFVA4Spcgg"
title="YouTube video"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
referrerpolicy="strict-origin-when-cross-origin"
style="position:absolute;inset:0;width:100%;height:100%;border:0;"
allowfullscreen>
&lt;/iframe>
&lt;/div>
&lt;p>TDD in a nutshell; it’s about the rhythm.&lt;/p>
&lt;ol>
&lt;li>Specify what you want.&lt;/li>
&lt;li>Make it work.&lt;/li>
&lt;li>Make it better.&lt;/li>
&lt;/ol>
&lt;hr />
&lt;h2 id="kent-beck">Kent Beck
&lt;a class="heading-anchor" href="#kent-beck" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;blockquote class="twitter-tweet">&lt;p lang="en" dir="ltr">1. Change the code as usual&lt;br>2. Write a test that only passes after the change&lt;br>3. Revert to before 1&lt;br>4. Type the test again (copy/paste is cheating &amp;amp; invalidates the warranty of the exercise)&lt;br>5. Make it compile by changing the code&lt;br>6. See it fail&lt;br>7. Change the code to make it pass&lt;/p>&amp;mdash; Kent Beck 🌻 (@KentBeck) &lt;a href="https://twitter.com/KentBeck/status/1421257650113634304?ref_src=twsrc%5Etfw">July 30, 2021&lt;/a>&lt;/blockquote> &lt;script async src="https://platform.twitter.com/widgets.js" charset="utf-8">&lt;/script>
&lt;hr />
&lt;p>Images original by &lt;a rel="external" href="https://x.com/evrtrabajo">Emmanuel Valverde Ramos&lt;/a>.&lt;/p></content></entry><entry xml:lang="en"><title>To Mock or Not to Mock</title><subtitle>How to escape the mocking hell</subtitle><category term="testing" scheme="https://chemaclass.com/tags/testing/" label="Testing"/><category term="tdd" scheme="https://chemaclass.com/tags/tdd/" label="Tdd"/><category term="software-design" scheme="https://chemaclass.com/tags/software-design/" label="Software Design"/><category term="clean-code" scheme="https://chemaclass.com/tags/clean-code/" label="Clean Code"/><category term="php" scheme="https://chemaclass.com/tags/php/" label="Php"/><published>2021-01-11T00:00:00+00:00</published><updated>2021-01-11T00:00:00+00:00</updated><author><name>
Chemaclass</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/blog/to-mock-or-not-to-mock/"/><id>https://chemaclass.com/blog/to-mock-or-not-to-mock/</id><summary type="html">Mocking is useful, but 'what to mock' usually turns out to be a more complicated than expected if you don't treat this carefully.</summary><content type="html">&lt;p>Mocking is useful, but “what to mock” usually turns out to be more complicated than expected if you don’t treat
this carefully.&lt;/p>
&lt;span id="continue-reading">&lt;/span>&lt;h4 id="how-to-escape-the-mocking-hell">How to escape the mocking hell
&lt;a class="heading-anchor" href="#how-to-escape-the-mocking-hell" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h4>
&lt;p>What is actually happening when we create a mock? Which types of mocks are there? Is mocking good or bad? Well, as
always, everything depends on the context. And here we will consider some of the main situations about when to mock and
when not to mock, but especially why.&lt;/p>
&lt;h2 id="what-happens-when-you-mock-something">What happens when you mock something?
&lt;a class="heading-anchor" href="#what-happens-when-you-mock-something" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>First, we should define what is a mock:&lt;/p>
&lt;blockquote>
&lt;p>In a unit test, mock objects can simulate the behavior of complex, real objects and are therefore useful when it is impractical or impossible to incorporate a real object into a unit test.&lt;/p>
&lt;/blockquote>
&lt;p>Mocking makes sense in a &lt;em>unit testing&lt;/em> context. An integration test should go through the real implementation checking
the integration between multiple units, which are even allowed to talk to the DB or File IO: infrastructure code.
Therefore we should agree that &lt;em>a unit test is a fast and deterministic test that doesn’t rely on external dependencies
and doesn’t require any special context to run&lt;/em>.&lt;/p>
&lt;p>Mock objects meet the &lt;em>interface&lt;/em> requirements. In consequence, they allow us to write and unit-test functionality
without calling complex underlying or collaborating classes.&lt;/p>
&lt;p>A mock is a test double that stands in for real implementation code during the unit testing process. It is also capable
of producing assertions about how it was manipulated by the test subject during the test run.&lt;/p>
&lt;blockquote>
&lt;p>I strongly recommend you to read this post if you want to get into the details of why &lt;a rel="external" href="https://medium.com/javascript-scene/mocking-is-a-code-smell-944a70c90a6a">Mocking is a code smell&lt;/a> (Topics like these: What is a mock? What is a unit test? What is test coverage? What is tight coupling? What causes tight coupling? What does composition have to do with mocking? How do we remove coupling? and more!)&lt;/p>
&lt;/blockquote>
&lt;h2 id="the-problem-with-mocking">The problem with mocking
&lt;a class="heading-anchor" href="#the-problem-with-mocking" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>When you mock you are overriding the logic of the mocked class. The real logic is getting hidden behind the scenes and
there is actually where bugs love to live. Consider that:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>The mock may have attributes, methods, or arguments that the real object doesn’t.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>The mock’s &lt;em>return values may differ from the real objects’ return values&lt;/em>. For example, it may return a different
type of object that has different attributes.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>The mock’s &lt;em>side effects and behavior may differ from the real objects’ ones&lt;/em>. For example, maybe the mock fails to
raise an exception when the real object would raise it.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="alternatives-to-mocking">Alternatives to mocking
&lt;a class="heading-anchor" href="#alternatives-to-mocking" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>“Are you saying that mocking is bad and we shouldn’t mock?!” No.&lt;/p>
&lt;p>It depends on what you are “overriding”.&lt;/p>
&lt;ul>
&lt;li>Is your business domain logic what you are mocking? Then it’s wrong.&lt;/li>
&lt;li>Is the connection to the DB what you are mocking? Then it’s right.&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>It depends on the context of the logic and where that logic belongs.&lt;/p>
&lt;/blockquote>
&lt;p>Is it part of your business domain logic? Then you shouldn’t mock it but instantiate it.&lt;/p>
&lt;p>Is it part of any infrastructure dependency like DB connection, IO file system, Network, or any external service that
has nothing to do directly with your business domain? Then &lt;em>mock it using abstractions/interfaces&lt;/em>.&lt;/p>
&lt;p>The interface should be the &lt;em>contract between your business domain logic and its external infrastructure dependencies&lt;/em>.
Imagine how easy it would be to unit test your domain logic by instantiating it and calling their methods with different
arguments expecting different inputs under your entire control.&lt;/p>
&lt;h2 id="some-tricks">Some tricks
&lt;a class="heading-anchor" href="#some-tricks" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>When you are writing a unit test:&lt;/p>
&lt;ul>
&lt;li>Try to instantiate your classes first.&lt;/li>
&lt;li>Avoid mocking concrete classes. I wrote an article exclusively about this:
encouraging &lt;a rel="external" href="https://medium.com/swlh/final-classes-in-php-9174e3e2747e">final classes&lt;/a> and interfaces.&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>Mock interfaces. Instantiate concrete classes.&lt;/p>
&lt;/blockquote>
&lt;div style="position:relative;aspect-ratio:16/9;width:100%;">
&lt;iframe
src="https://www.youtube-nocookie.com/embed/RbSqXFUfRMU"
title="YouTube video"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
referrerpolicy="strict-origin-when-cross-origin"
style="position:absolute;inset:0;width:100%;height:100%;border:0;"
allowfullscreen>
&lt;/iframe>
&lt;/div>
&lt;p>“Excessive use of mocks leads to legacy code.” - Philippe Boargau&lt;/p>
&lt;h3 id="how-can-we-avoid-excessive-mocking">How can we avoid excessive mocking?
&lt;a class="heading-anchor" href="#how-can-we-avoid-excessive-mocking" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>Favor immutable state over a mutable state.&lt;/li>
&lt;li>Make dependencies explicit.&lt;/li>
&lt;li>Program to an interface, not to an implementation.&lt;/li>
&lt;/ul>
&lt;p>&lt;img src="/images/blog/2021-01-11/footer.webp" alt="mock interfaces, instantiate concrete classes" />&lt;/p>
&lt;hr />
&lt;h4 id="references">References
&lt;a class="heading-anchor" href="#references" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h4>
&lt;ul>
&lt;li>&lt;a rel="external" href="https://medium.com/javascript-scene/mocking-is-a-code-smell-944a70c90a6a">Mocking is a code smell&lt;/a> - Eric Elliott&lt;/li>
&lt;li>&lt;a rel="external" href="https://blog.cleancoder.com/uncle-bob/2014/05/10/WhenToMock.html">When to mock&lt;/a> &amp;amp; &lt;a rel="external" href="https://blog.cleancoder.com/uncle-bob/2017/05/05/TestDefinitions.html">Test Definitions&lt;/a> - Uncle Bob&lt;/li>
&lt;li>&lt;a rel="external" href="https://matthiasnoback.nl/2018/09/final-classes-by-default-why/">Final classes by default&lt;/a> - Matthias Noback&lt;/li>
&lt;li>&lt;a rel="external" href="https://www.seanh.cc/2017/03/17/the-problem-with-mocks/">The problem with mocks&lt;/a> - Sean Hammond&lt;/li>
&lt;li>&lt;a rel="external" href="https://www.artima.com/weblogs/viewpost.jsp?thread=126923">A Set of Unit Testing Rules&lt;/a> - Michael Feathers&lt;/li>
&lt;/ul></content></entry><entry xml:lang="en"><title>Testing Effectively Legacy Code</title><subtitle>How to write proper tests to already written code</subtitle><category term="testing" scheme="https://chemaclass.com/tags/testing/" label="Testing"/><category term="refactoring" scheme="https://chemaclass.com/tags/refactoring/" label="Refactoring"/><category term="clean-code" scheme="https://chemaclass.com/tags/clean-code/" label="Clean Code"/><category term="tdd" scheme="https://chemaclass.com/tags/tdd/" label="Tdd"/><published>2020-08-17T00:00:00+00:00</published><updated>2020-08-17T00:00:00+00:00</updated><author><name>
Chemaclass</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/blog/testing-effectively-legacy-code/"/><id>https://chemaclass.com/blog/testing-effectively-legacy-code/</id><summary type="html">How to write characterization tests for legacy code to safely refactor without breaking existing behavior.</summary><content type="html">&lt;p>These tests are also known as Characterization tests.&lt;/p>
&lt;span id="continue-reading">&lt;/span>
&lt;blockquote>
&lt;p>A characterization test describes the actual behavior of an existing piece of software, and therefore protects existing
behavior of legacy code against unintended changes via automated testing. This term was coined by &lt;a href="/readings/working-effectively-with-legacy-code/">Michael Feathers&lt;/a>.&lt;/p>
&lt;/blockquote>
&lt;p>They enable and provide a safety net for extending and refactoring code that does not have adequate tests. A test can be
written that asserts that the output of the legacy code matches the observed result for the given inputs.&lt;/p>
&lt;h2 id="how-to-start">How to start?
&lt;a class="heading-anchor" href="#how-to-start" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>These are my learnings one year after
reading &lt;a href="/readings/working-effectively-with-legacy-code/">Working Effectively with Legacy Code&lt;/a> and applying it to the
different projects I’ve been working on since then.&lt;/p>
&lt;h3 id="1-what-do-you-want-to-test">1. What do you want to test?
&lt;a class="heading-anchor" href="#1-what-do-you-want-to-test" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Find out the assertions. Create a test file for your class, and a testing method for the function that you want to test.
Hint:&lt;/p>
&lt;ul>
&lt;li>If you have the following method &lt;code>applySomeLogic(): ReturnType&lt;/code>,&lt;/li>
&lt;li>the test you could write is &lt;code>test_apply_some_logic(): void&lt;/code>.&lt;/li>
&lt;/ul>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="php">&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);">final&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> class&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);"> MyBusinessLogic&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>{&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);"> private&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> DependencyInterface&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> dependencyInterface&lt;/span>&lt;span>;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);"> private&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> ConcreteDependency&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> concrete&lt;/span>&lt;span>;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);"> public&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> function&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> __construct&lt;/span>&lt;span>(&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> DependencyInterface dependencyInterface&lt;/span>&lt;span>,&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> ConcreteDependency concrete&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> )&lt;/span>&lt;span> {&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);"> this&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">.&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">dependencyInterface&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> dependencyInterface&lt;/span>&lt;span>;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);"> this&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">.&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">concrete&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> concrete&lt;/span>&lt;span>;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> }&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);"> public&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> function&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);"> applySomeLogic&lt;/span>&lt;span>(&lt;/span>&lt;span>Input input&lt;/span>&lt;span>)&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">:&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> ReturnType&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> {&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#6A737D, #6A737D);"> //&lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);"> black box responsible to create a ReturnType&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#6A737D, #6A737D);"> //&lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);"> based on the given Input&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);"> return&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> returnType&lt;/span>&lt;span>;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> }&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>}&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);">final&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> class&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);"> MyBusinessLogicTest&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> extends&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);"> TestCase&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>{&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);"> public&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> function&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);"> test_apply_some_logic&lt;/span>&lt;span>(&lt;/span>&lt;span>)&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">:&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> void&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> {&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#6A737D, #6A737D);"> //&lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);"> I want to assert that &amp;quot;applying some logic&amp;quot;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#6A737D, #6A737D);"> //&lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);"> from MyBusinessLogic with the given Input&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#6A737D, #6A737D);"> //&lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);"> I will receive a concrete ReturnType with a &lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#6A737D, #6A737D);"> //&lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);"> certain value as its property. Something like:&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> &lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);"> returnType&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> myBusinessLogic&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">.&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);">applySomeLogic&lt;/span>&lt;span>(&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">input&lt;/span>&lt;span>)&lt;/span>&lt;span>;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#6F42C1, #B392F0);"> assertEquals&lt;/span>&lt;span>(&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">&amp;#39;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">expected&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">&amp;#39;&lt;/span>&lt;span>,&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> returnType&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">.&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);">getProperty&lt;/span>&lt;span>(&lt;/span>&lt;span>)&lt;/span>&lt;span>)&lt;/span>&lt;span>;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> }&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>}&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;h3 id="2-instantiate-the-concrete-final-class-that-you-want-to-test">2. Instantiate the concrete/final class that you want to test.
&lt;a class="heading-anchor" href="#2-instantiate-the-concrete-final-class-that-you-want-to-test" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Do not mock your concrete classes. Especially your business domain. Mock only interfaces. Otherwise, you can be hiding
bugs unintentionally (with green/passing tests!). Treat your &lt;a href="/blog/final-classes">business domain classes as final&lt;/a>.&lt;/p>
&lt;p>Either mock the interface or instantiate an anonymous class if you want to create a Stub:&lt;/p>
&lt;blockquote>
&lt;p>Stubs provide answers to calls made during the test, usually not responding to anything outside what’s programmed in for the test.&lt;/p>
&lt;/blockquote>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="php">&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);">final&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> class&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);"> MyBusinessLogicTest&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> extends&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);"> TestCase&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>{&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);"> public&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> function&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);"> test_apply_some_logic&lt;/span>&lt;span>(&lt;/span>&lt;span>)&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">:&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> void&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> {&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);"> myBusinessLogic&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> new&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> MyBusinessLogic&lt;/span>&lt;span>(&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);"> this&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">.&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);">createMock&lt;/span>&lt;span>(&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">DependencyInterface&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">.&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">class&lt;/span>&lt;span>)&lt;/span>&lt;span>,&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);"> new&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> ConcreteDependency&lt;/span>&lt;span>(&lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);">/*&lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);"> ... &lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);">*/&lt;/span>&lt;span>)&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> )&lt;/span>&lt;span>;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#6A737D, #6A737D);"> //&lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);"> OR&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);"> myBusinessLogic&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> new&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> MyBusinessLogic&lt;/span>&lt;span>(&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);"> new&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> FakeDependency&lt;/span>&lt;span>(&lt;/span>&lt;span>)&lt;/span>&lt;span>,&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);"> new&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> ConcreteDependency&lt;/span>&lt;span>(&lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);">/*&lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);"> ... &lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);">*/&lt;/span>&lt;span>)&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> )&lt;/span>&lt;span>;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#6A737D, #6A737D);"> //&lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);"> ...&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> }&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>}&lt;/span>&lt;/span>&lt;/code>&lt;/pre>
&lt;blockquote>
&lt;p>Where &lt;code>FakeDependency&lt;/code> is a concrete implementation of &lt;code>DependencyInterface&lt;/code> with already “fake data/implementation” that it’s useful only for testing purposes.&lt;/p>
&lt;/blockquote>
&lt;h3 id="3-call-the-method-from-that-class-providing-the-desired-input">3. Call the method from that class providing the desired input.
&lt;a class="heading-anchor" href="#3-call-the-method-from-that-class-providing-the-desired-input" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>The output will be determined by the initial state of the business logic class that we want to test PLUS the input
arguments that we are using.&lt;/p>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="php">&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);">input&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> new&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> Input&lt;/span>&lt;span>(&lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);">/*&lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);"> ... &lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);">*/&lt;/span>&lt;span>)&lt;/span>&lt;span>;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);">returnType&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> myBusinessLogic&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">.&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);">applySomeLogic&lt;/span>&lt;span>(&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">input&lt;/span>&lt;span>)&lt;/span>&lt;span>;&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;h3 id="4-assert-the-output-with-the-expected-value">4. Assert the output with the expected value.
&lt;a class="heading-anchor" href="#4-assert-the-output-with-the-expected-value" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>From step-1 you need to know what you want. Apply the assertion(s) now.&lt;/p>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="php">&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);">final&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> class&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);"> MyBusinessLogicTest&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> extends&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);"> TestCase&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>{&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);"> public&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> function&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);"> test_apply_some_logic&lt;/span>&lt;span>(&lt;/span>&lt;span>)&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">:&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> void&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> {&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);"> myBusinessLogic&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> new&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> MyBusinessLogic&lt;/span>&lt;span>(&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);"> this&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">.&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);">createMock&lt;/span>&lt;span>(&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">DependencyInterface&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">::&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">class&lt;/span>&lt;span>)&lt;/span>&lt;span>,&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);"> new&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> ConcreteDependency&lt;/span>&lt;span>(&lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);">/*&lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);"> ... &lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);">*/&lt;/span>&lt;span>)&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> )&lt;/span>&lt;span>;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);"> input&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> new&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> Input&lt;/span>&lt;span>(&lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);">/*&lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);"> ... &lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);">*/&lt;/span>&lt;span>)&lt;/span>&lt;span>;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);"> returnType&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> myBusinessLogic&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">.&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);">applySomeLogic&lt;/span>&lt;span>(&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">input&lt;/span>&lt;span>)&lt;/span>&lt;span>;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#6F42C1, #B392F0);"> assertEquals&lt;/span>&lt;span>(&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">&amp;#39;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">expected&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">&amp;#39;&lt;/span>&lt;span>,&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> returnType&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">.&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);">getProperty&lt;/span>&lt;span>(&lt;/span>&lt;span>)&lt;/span>&lt;span>)&lt;/span>&lt;span>;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> }&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>}&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;h3 id="5-you-might-want-to-assert-different-expected-values">5. You might want to assert different expected values.
&lt;a class="heading-anchor" href="#5-you-might-want-to-assert-different-expected-values" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>You can easily provide different arguments to your business logic either via the logic construction or different given
arguments. To do so, use the @dataProvider annotation. The “dataProvider” method must be public and return any iterable.&lt;/p>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="php">&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);">final&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> class&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);"> MyBusinessLogicTest&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> extends&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);"> TestCase&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>{&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#6A737D, #6A737D);"> /**&lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);"> @dataProvider providerApplySomeLogic &lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);">*/&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);"> public&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> function&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);"> test_apply_some_logic&lt;/span>&lt;span>(&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> array concreteMapping&lt;/span>&lt;span>,&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> string argInput&lt;/span>&lt;span>,&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> string expectedValue&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> )&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">:&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> void&lt;/span>&lt;span> {&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);"> myBusinessLogic&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> new&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> MyBusinessLogic&lt;/span>&lt;span>(&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);"> this&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">.&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);">createMock&lt;/span>&lt;span>(&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">DependencyInterface&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">.&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">class&lt;/span>&lt;span>)&lt;/span>&lt;span>,&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);"> new&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> ConcreteDependency&lt;/span>&lt;span>(&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">concreteMapping&lt;/span>&lt;span>)&lt;/span>&lt;span>,&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#6A737D, #6A737D);"> /*&lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);"> ... &lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);">*/&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> )&lt;/span>&lt;span>;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);"> input&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> new&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> Input&lt;/span>&lt;span>(&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">argInput&lt;/span>&lt;span>,&lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);"> /*&lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);"> ... &lt;/span>&lt;span style="color: light-dark(#6A737D, #6A737D);">*/&lt;/span>&lt;span>)&lt;/span>&lt;span>;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);"> actual&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> myBusinessLogic&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">.&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);">applySomeLogic&lt;/span>&lt;span>(&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">input&lt;/span>&lt;span>)&lt;/span>&lt;span>;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#6F42C1, #B392F0);"> assertEquals&lt;/span>&lt;span>(&lt;/span>&lt;span>$&lt;/span>&lt;span>expectedValue&lt;/span>&lt;span>,&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> actual&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">.&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);">getProperty&lt;/span>&lt;span>(&lt;/span>&lt;span>)&lt;/span>&lt;span>)&lt;/span>&lt;span>;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> }&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);"> public&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> function&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);"> providerApplySomeLogic&lt;/span>&lt;span>(&lt;/span>&lt;span>)&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">:&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> Generator&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> {&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);"> yield&lt;/span>&lt;span> [&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#032F62, #9ECBFF);"> &amp;#39;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">concreteMapping&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">&amp;#39;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&amp;gt;&lt;/span>&lt;span> [&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">&amp;#39;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">key&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">&amp;#39;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&amp;gt;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);"> &amp;#39;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">value&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">&amp;#39;&lt;/span>&lt;span>]&lt;/span>&lt;span>,&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#032F62, #9ECBFF);"> &amp;#39;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">argInput&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">&amp;#39;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&amp;gt;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);"> &amp;#39;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">something&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">&amp;#39;&lt;/span>&lt;span>,&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#032F62, #9ECBFF);"> &amp;#39;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">expectedValue&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">&amp;#39;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&amp;gt;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);"> &amp;#39;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">expected-value-A&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">&amp;#39;&lt;/span>&lt;span>,&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> ]&lt;/span>&lt;span>;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#D73A49, #F97583);"> yield&lt;/span>&lt;span> [&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#032F62, #9ECBFF);"> &amp;#39;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">concreteMapping&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">&amp;#39;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&amp;gt;&lt;/span>&lt;span> [&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">&amp;#39;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">key2&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">&amp;#39;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&amp;gt;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);"> &amp;#39;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">value2&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">&amp;#39;&lt;/span>&lt;span>]&lt;/span>&lt;span>,&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#032F62, #9ECBFF);"> &amp;#39;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">argInput&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">&amp;#39;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&amp;gt;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);"> &amp;#39;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">something-else&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">&amp;#39;&lt;/span>&lt;span>,&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#032F62, #9ECBFF);"> &amp;#39;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">expectedValue&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">&amp;#39;&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&amp;gt;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);"> &amp;#39;&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">expected-value-B&lt;/span>&lt;span style="color: light-dark(#032F62, #9ECBFF);">&amp;#39;&lt;/span>&lt;span>,&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> ]&lt;/span>&lt;span>;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span> }&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span>}&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;h3 id="lastly-clean-what-you-did">Lastly: clean what you did.
&lt;a class="heading-anchor" href="#lastly-clean-what-you-did" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Yes, clean the tests. They deserve to be as clean as your production code. Otherwise, they will rot as time passes by and
remain dirty for your colleagues and your future self!&lt;/p>
&lt;p>For example, you can apply extract method refactoring to move out the implementation details (of the creation of the
different objects) and keep the same abstraction level while reading the test code.&lt;/p>
&lt;pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);">&lt;code data-lang="php">&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);">myBusinessLogic&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> this&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">.&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);">createBusinessLogic&lt;/span>&lt;span>(&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">concreteMapping&lt;/span>&lt;span>)&lt;/span>&lt;span>;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);">input&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> this&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">.&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);">createInput&lt;/span>&lt;span>(&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">argInput&lt;/span>&lt;span>)&lt;/span>&lt;span>;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#005CC5, #79B8FF);">actual&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);"> =&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> myBusinessLogic&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">.&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);">applySomeLogic&lt;/span>&lt;span>(&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">input&lt;/span>&lt;span>)&lt;/span>&lt;span>;&lt;/span>&lt;/span>
&lt;span class="giallo-l">&lt;span style="color: light-dark(#6F42C1, #B392F0);">assertEquals&lt;/span>&lt;span>(&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);">expectedValue&lt;/span>&lt;span>,&lt;/span>&lt;span style="color: light-dark(#005CC5, #79B8FF);"> actual&lt;/span>&lt;span style="color: light-dark(#D73A49, #F97583);">.&lt;/span>&lt;span style="color: light-dark(#6F42C1, #B392F0);">getProperty&lt;/span>&lt;span>(&lt;/span>&lt;span>)&lt;/span>&lt;span>)&lt;/span>&lt;span>;&lt;/span>&lt;/span>&lt;/code>&lt;/pre>
&lt;p>Of course, everything depends on the context. Does it really make sense to extract into a private method the
createBusinessLogic() or even createInput()? Well, that’s up to you. It depends on the number of lines and, most
importantly, the abstraction level that belongs to that context.&lt;/p>
&lt;blockquote>
&lt;p>Just remember: keep your methods small.&lt;/p>
&lt;/blockquote>
&lt;p>Now you can refactor the production code that you covered with tests without that fear of breaking it.&lt;/p>
&lt;hr />
&lt;h3 id="all-together">All together
&lt;a class="heading-anchor" href="#all-together" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;script src="https://gist.github.com/Chemaclass&amp;#x2F;07704606fcb337dbb0881c94197c329e.js">&lt;/script>
&lt;script src="https://gist.github.com/Chemaclass&amp;#x2F;9f7f96242153b696b3f8da5c7fa80461.js">&lt;/script>
&lt;hr />
&lt;h2 id="legacy-code-is-code-without-tests">Legacy Code is code without tests
&lt;a class="heading-anchor" href="#legacy-code-is-code-without-tests" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>&lt;img src="/images/blog/2020-08-17/footer.jpg" alt="legacy code is code without tests" />&lt;/p>
&lt;p>Of course, there is way more to learn
about &lt;a href="/readings/working-effectively-with-legacy-code/">testing and working with legacy code&lt;/a>. In fact, especially when
dealing with legacy code, you will encounter situations where the code is coupled somehow that you might want to mock
your concrete classes because there is no interface (yet) for it.&lt;/p>
&lt;p>This book presents to you a lot of techniques about when, why, where, and how you can apply these changes.&lt;/p>
&lt;blockquote>
&lt;p>When working with code you need &lt;strong>feedback&lt;/strong>. Automated feedback is the best. Thus, this is the first thing you need to do: write the tests.&lt;/p>
&lt;/blockquote>
&lt;h3 id="first-add-tests-then-do-your-changes">First, add tests, then do your changes.
&lt;a class="heading-anchor" href="#first-add-tests-then-do-your-changes" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;h4 id="change-as-little-code-as-possible-to-get-tests-in-place-with-the-recipe">Change as little code as possible to get tests in place with the recipe:
&lt;a class="heading-anchor" href="#change-as-little-code-as-possible-to-get-tests-in-place-with-the-recipe" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h4>
&lt;ol>
&lt;li>Identify “change points” to break your code dependencies.&lt;/li>
&lt;li>Break dependencies.&lt;/li>
&lt;li>Write the tests.&lt;/li>
&lt;li>Make your changes.&lt;/li>
&lt;li>Refactor.&lt;/li>
&lt;/ol>
&lt;hr />
&lt;div style="position:relative;aspect-ratio:16/9;width:100%;">
&lt;iframe
src="https://www.youtube-nocookie.com/embed/wRtJRkRIa2s"
title="YouTube video"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
referrerpolicy="strict-origin-when-cross-origin"
style="position:absolute;inset:0;width:100%;height:100%;border:0;"
allowfullscreen>
&lt;/iframe>
&lt;/div></content></entry><entry xml:lang="en"><title>The Art of Testing: Where Design Meets Quality</title><subtitle>From a software developer's point of view</subtitle><category term="testing" scheme="https://chemaclass.com/tags/testing/" label="Testing"/><category term="software-design" scheme="https://chemaclass.com/tags/software-design/" label="Software Design"/><category term="clean-code" scheme="https://chemaclass.com/tags/clean-code/" label="Clean Code"/><category term="tdd" scheme="https://chemaclass.com/tags/tdd/" label="Tdd"/><published>2020-04-07T00:00:00+00:00</published><updated>2020-04-07T00:00:00+00:00</updated><author><name>
Chemaclass</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/blog/the-art-of-testing/"/><id>https://chemaclass.com/blog/the-art-of-testing/</id><summary type="html">Why you should consider testing as part of your daily development habit and how it's directly linked to the software quality.</summary><content type="html">&lt;p>Why you should consider testing as part of your daily development habit and how it’s directly linked to the software
quality.&lt;/p>
&lt;span id="continue-reading">&lt;/span>
&lt;p>This post intends not to explain the different testing techniques that we can use. I’m not going to tell you the differences between unit, integration, feature, or end-to-end testing.&lt;/p>
&lt;p>I’m still amazed by the lack of experience with testing in software in general. Common ignorance in this world about
best testing practices for us as developers. Inexperience that you can easily see if you have already worked on
different projects and teams.&lt;/p>
&lt;h3 id="software-testing">Software testing
&lt;a class="heading-anchor" href="#software-testing" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Some horrible patterns I’ve seen (and done):&lt;/p>
&lt;ul>
&lt;li>Testing for the sake of testing: testing every single file, sometimes wrongly considered a unit.&lt;/li>
&lt;li>Mocking every class we intend to test, overriding the actual implementation, and creating a fake behavior,
providing a false coverage perception.&lt;/li>
&lt;li>Coupling production code with tests everywhere, so it’s impossible to change anything without breaking some tests,
even if the feature itself it’s working as intended.&lt;/li>
&lt;li>Not testing at all because “why should we even test anything if the feature is done, and it works? Why should we
spend more time on this if it’s done?.”&lt;/li>
&lt;/ul>
&lt;p>One of the main reasons for software testing is actually verifying a suite of proofs for the expected behavior of the
final software piece. However, testing can (and should) be more than that.&lt;/p>
&lt;h3 id="software-design">Software design
&lt;a class="heading-anchor" href="#software-design" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Software design goes from algorithm to architecture design. Even when I believe these two levels of components have
different needs and requirements, they still share some common patterns. For example, testing, and this is what we are
going to talk about right now:&lt;/p>
&lt;blockquote>
&lt;p>If it’s easy to test, it will likely be because of good design.&lt;/p>
&lt;/blockquote>
&lt;h3 id="software-quality">Software quality
&lt;a class="heading-anchor" href="#software-quality" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Is quality hard to measure out? Indeed. There are different measurement keys that we should take while considering
quality for any piece of software. Still, I’m sure we could agree on this:&lt;/p>
&lt;blockquote>
&lt;p>If you aim for quality in your software, you better seek a good design.&lt;/p>
&lt;/blockquote>
&lt;p>Testing by itself means “proving,” as we all know. That said… how difficult it sometimes turns to prove some logic
that we finally give up because of its complexity itself?&lt;/p>
&lt;p>The art of testing is about using testing itself to help and contribute to the final result. To encourage good design,
suppose we’re able to use testing (of any kind) in our favor, depending on the context of what we want to prove. In that
case, it will undoubtedly help us increase the product’s end quality.&lt;/p>
&lt;p>Therefore, testing should be used not only to prove the behavior of our software but also to guide our software to a better design.&lt;/p>
&lt;p>Should we test everything? Well, that’s the million-dollar question. In my opinion, everything depends on the context. We
might encounter situations where tests might not be beneficial. Even in those situations, we should write our code as if
it could be tested anyway.&lt;/p>
&lt;p>&lt;img src="/images/blog/2020-04-07/footer.webp" alt="testable code and good design" />&lt;/p>
&lt;blockquote>
&lt;p>Testable code tends to better design and, therefore, better quality.&lt;/p>
&lt;/blockquote></content></entry><entry xml:lang="en"><title>Clean Agile</title><subtitle>Back to Basics</subtitle><category term="agile" scheme="https://chemaclass.com/tags/agile/" label="Agile"/><category term="tdd" scheme="https://chemaclass.com/tags/tdd/" label="Tdd"/><category term="software-design" scheme="https://chemaclass.com/tags/software-design/" label="Software Design"/><published>2020-03-12T00:00:00+00:00</published><updated>2020-03-12T00:00:00+00:00</updated><author><name>
Robert C. Martin</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/readings/clean-agile/"/><id>https://chemaclass.com/readings/clean-agile/</id><summary type="html">This book is about Agile. What it was, what it is, and what it will be. This is a back-to-basics talk that covers the history of Agile, what motivated it, and what has happened to it since.</summary><content type="html">&lt;span id="continue-reading">&lt;/span>
&lt;p>Clean Agile comes from Uncle Bob, one of the founding fathers of Agile, one of the seventeen people who authored the
&lt;a rel="external" href="https://agilemanifesto.org/">Agile Manifesto&lt;/a> back in 2001.&lt;/p>
&lt;hr />
&lt;p>This talk is about Agile. What it was, what it is, and what it will be. This is a back-to-basics talk that covers the
history of Agile, what motivated it, and what has happened to it since. The talk covers the basic practices of Agile,
and compares and contrasts those practices with the current menagerie of Agile processes.&lt;/p>
&lt;div style="position:relative;aspect-ratio:16/9;width:100%;">
&lt;iframe
src="https://www.youtube-nocookie.com/embed/FedQ2NlgxMI"
title="YouTube video"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
referrerpolicy="strict-origin-when-cross-origin"
style="position:absolute;inset:0;width:100%;height:100%;border:0;"
allowfullscreen>
&lt;/iframe>
&lt;/div></content></entry><entry xml:lang="en"><title>Extreme Programming Explained</title><subtitle>Embrace Change</subtitle><category term="xp" scheme="https://chemaclass.com/tags/xp/" label="Xp"/><category term="agile" scheme="https://chemaclass.com/tags/agile/" label="Agile"/><category term="tdd" scheme="https://chemaclass.com/tags/tdd/" label="Tdd"/><category term="pair-programming" scheme="https://chemaclass.com/tags/pair-programming/" label="Pair Programming"/><category term="communication" scheme="https://chemaclass.com/tags/communication/" label="Communication"/><published>2020-03-05T00:00:00+00:00</published><updated>2020-03-05T00:00:00+00:00</updated><author><name>
Kent Beck</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/readings/extreme-programming-explained/"/><id>https://chemaclass.com/readings/extreme-programming-explained/</id><summary type="html">Extreme Programming (XP) is an agile software development framework that aims to produce higher quality software, and higher quality of life for the development team. XP is the most specific of the agile frameworks regarding appropriate engineering practices for software development.</summary><content type="html">&lt;span id="continue-reading">&lt;/span>&lt;h2 id="definition">Definition
&lt;a class="heading-anchor" href="#definition" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Extreme Programming (XP) is an agile software development framework that aims to produce higher quality software, and
higher quality of life for the development team. XP is the most specific of the agile frameworks regarding appropriate
engineering practices for software development.&lt;/p>
&lt;hr />
&lt;h2 id="values">Values
&lt;a class="heading-anchor" href="#values" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>The five values of XP are communication, simplicity, feedback, courage, and respect and are described in more detail
below.&lt;/p>
&lt;h3 id="communication">Communication
&lt;a class="heading-anchor" href="#communication" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Software development is inherently a team sport that relies on communication to transfer knowledge from one team member
to everyone else on the team. XP stresses the importance of the appropriate kind of communication: face to face
discussion with the aid of a white board or other drawing mechanism.&lt;/p>
&lt;h3 id="simplicity">Simplicity
&lt;a class="heading-anchor" href="#simplicity" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Simplicity means “what is the simplest thing that will work?” The purpose of this is to avoid waste and do only
absolutely necessary things such as keep the design of the system as simple as possible so that it is easier to
maintain, support, and revise. Simplicity also means address only the requirements that you know about; don’t try to
predict the future.&lt;/p>
&lt;h3 id="feedback">Feedback
&lt;a class="heading-anchor" href="#feedback" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Through constant feedback about their previous efforts, teams can identify areas for improvement and revise their
practices. Feedback also supports simple design. Your team builds something, gathers feedback on your design and
implementation, and then adjust your product going forward.&lt;/p>
&lt;h3 id="courage">Courage
&lt;a class="heading-anchor" href="#courage" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Kent Beck defined courage as “effective action in the face of fear”. This definition shows a preference for action based
on other principles so that the results aren’t harmful to the team. You need courage…&lt;/p>
&lt;ul>
&lt;li>to raise organizational issues that reduce your team’s effectiveness.&lt;/li>
&lt;li>to stop doing something that doesn’t work and try something else.&lt;/li>
&lt;li>to accept and act on feedback, even when it’s difficult to accept.&lt;/li>
&lt;/ul>
&lt;h3 id="respect">Respect
&lt;a class="heading-anchor" href="#respect" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>The members of your team need to respect each other in order to communicate with each other, provide and accept feedback
that honors your relationship, and to work together to identify simple designs and solutions.&lt;/p>
&lt;hr />
&lt;h2 id="principles">Principles
&lt;a class="heading-anchor" href="#principles" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;h3 id="humanity">Humanity
&lt;a class="heading-anchor" href="#humanity" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Human beings are the ones developing software. It is a fact. The book mentions 5 points that are needed for developers
to become good: basic safety, accomplishment, belonging, growth, and intimacy.&lt;/p>
&lt;p>The magic of great teams is that after the team members develop trust they find that they are free to be more themselves
as a result of their work together.&lt;/p>
&lt;h3 id="economics">Economics
&lt;a class="heading-anchor" href="#economics" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Software costs. Someone or multiple people paid or invested in it.&lt;/p>
&lt;p>Make sure what you are doing has business value, meets business goals, and serves business needs. For example, solving
the highest priority business need first maximizes the value of the project.&lt;/p>
&lt;p>The earlier software makes money, the sooner the development is valuable.&lt;/p>
&lt;h3 id="mutual-benefit">Mutual Benefit
&lt;a class="heading-anchor" href="#mutual-benefit" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Mutual benefit in XP is about activities benefitting all concerned. This principle is about finding practices that
benefit me now, me later, and the customers as well.&lt;/p>
&lt;p>The book brings up 3 points how XP mutually deals with communication-with-the-future problems:&lt;/p>
&lt;ul>
&lt;li>I write automated tests that help me design and implement better today. I leave these tests for future programmers to
use as well. This practice benefits me now and maintainers down the road.&lt;/li>
&lt;li>I carefully refactor to remove accidental complexity, giving me both satisfaction and fewer defects and making the
code easier to understand for those who encounter it later.&lt;/li>
&lt;li>I choose names from a coherent and explicit set of metaphors which speeds my development and makes the code clearer to
new programmers.&lt;/li>
&lt;/ul>
&lt;h3 id="self-similarity">Self-Similarity
&lt;a class="heading-anchor" href="#self-similarity" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>This principle is about copying the structure of one solution into a new context.&lt;/p>
&lt;p>For example, the basic structure of development is that you write a failing test and then make it work. This structure
operates at all different scales. Take into account, this principle is a good start, but it may not always work.&lt;/p>
&lt;h3 id="improvement">Improvement
&lt;a class="heading-anchor" href="#improvement" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Do your best today but strive to do better tomorrow, strive to have a deeper understanding tomorrow. XP shines in this
aspect, it is about always improving.&lt;/p>
&lt;blockquote>
&lt;p>Put improvement to work by not waiting for perfection. Find a starting place, get started, and improve from there.&lt;/p>
&lt;/blockquote>
&lt;h3 id="diversity">Diversity
&lt;a class="heading-anchor" href="#diversity" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Teams need to bring in people from different backgrounds, with different experiences, attitudes, etc. In order for the
team to have different ways of thinking and solving a problem.&lt;/p>
&lt;p>The principle of diversity suggests that the programmers should work together on the problem and both opinions should be valued.&lt;/p>
&lt;h3 id="reflection">Reflection
&lt;a class="heading-anchor" href="#reflection" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Good teams reflect after action, regularly. They think about why and how they are working.&lt;/p>
&lt;ul>
&lt;li>Why did we succeed? What should we continue doing?&lt;/li>
&lt;li>Why did we fail? What can we do better or differently?&lt;/li>
&lt;/ul>
&lt;p>Reflect and strive to improve. Even if everything seems perfect, know that there is always room for improvement and
throw in the question:&lt;/p>
&lt;ul>
&lt;li>Why do things seem perfect? What are we doing well? What can we do better in order to succeed even more?&lt;/li>
&lt;/ul>
&lt;h3 id="flow">Flow
&lt;a class="heading-anchor" href="#flow" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Flow in software development is delivering a steady flow of valuable software by engaging in all the activities of
development simultaneously. Don’t deliver software in big portions. Deploy smaller increments of value more frequently.&lt;/p>
&lt;h3 id="opportunity">Opportunity
&lt;a class="heading-anchor" href="#opportunity" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Learn to see problems as opportunities for learning and improving.&lt;/p>
&lt;blockquote>
&lt;p>Part of being extreme is consciously choosing to transform each problem into an opportunity:
an opportunity for personal growth, deepening relationships, and improved software.&lt;/p>
&lt;/blockquote>
&lt;h3 id="redundancy">Redundancy
&lt;a class="heading-anchor" href="#redundancy" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>The difficult problems in software development should be solved in multiple ways.&lt;/p>
&lt;blockquote>
&lt;p>The cost of the redundancy is more than paid for by the savings from not having a disaster.&lt;/p>
&lt;/blockquote>
&lt;h3 id="failure">Failure
&lt;a class="heading-anchor" href="#failure" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Sometimes it is extremely difficult to implement something, we don’t know which way or approach to take, try the ideas
you have, even if they fail! Failure isn’t a waste, rather a learning experience.&lt;/p>
&lt;p>Be aware of falling into the trap of discussing or thinking forever and not getting things done.&lt;/p>
&lt;blockquote>
&lt;p>When you don’t know what to do though, risking failure can be the shortest, surest road to success.&lt;/p>
&lt;/blockquote>
&lt;h3 id="quality">Quality
&lt;a class="heading-anchor" href="#quality" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Projects don’t go faster by lowering the quality. Actually it’s often the other way around (if not always). It results
in later and less predictable delivery, especially due to the amount of time spent on fixing bugs for example.&lt;/p>
&lt;p>Pushing quality higher often results in faster delivery.&lt;/p>
&lt;blockquote>
&lt;p>A concern for quality is no excuse for inaction. If you don’t know a clean way to do a job that has to be done,
do it the best way you can. If you know a clean way but it would take too long, do the job as well as you have time
for now. Resolve to finish doing it the clean way later.&lt;/p>
&lt;/blockquote>
&lt;h3 id="baby-steps">Baby Steps
&lt;a class="heading-anchor" href="#baby-steps" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Take baby steps. Making big changes in big steps is dangerous. People and teams can take many small steps so they appear
to be moving forward rapidly.&lt;/p>
&lt;blockquote>
&lt;p>Baby steps acknowledge that the overhead of small steps is much less than when a team wastefully recoils from aborted big changes.&lt;/p>
&lt;/blockquote>
&lt;h3 id="accepted-responsibility">Accepted Responsibility
&lt;a class="heading-anchor" href="#accepted-responsibility" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;blockquote>
&lt;p>Responsibility cannot be assigned; it can only be accepted. If someone tries to give you responsibility, only you can decide if you are responsible or if you aren’t.&lt;/p>
&lt;/blockquote>
&lt;hr />
&lt;h2 id="practices">Practices
&lt;a class="heading-anchor" href="#practices" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>While it is possible to do these practices in isolation, many teams have found some practices reinforce the others and
should be done in conjunction to fully eliminate the risks you often face in software development.&lt;/p>
&lt;h3 id="sit-together">Sit Together
&lt;a class="heading-anchor" href="#sit-together" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Since communication is one of the five values of XP, have your team sit together in the same space without barriers to
communication, such as cubicle walls.&lt;/p>
&lt;h3 id="whole-team">Whole Team
&lt;a class="heading-anchor" href="#whole-team" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Include on the team people with all the skills and perspectives necessary for the project to succeed.&lt;/p>
&lt;h3 id="informative-workspace">Informative Workspace
&lt;a class="heading-anchor" href="#informative-workspace" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Set up your team space to facilitate face to face communication, allow people to have some privacy when they need it,
and make the work of the team transparent to each other and to interested parties outside the team.&lt;/p>
&lt;h3 id="energized-work">Energized Work
&lt;a class="heading-anchor" href="#energized-work" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>You are most effective at software development and all knowledge work when you are focused and free from distractions.&lt;/p>
&lt;h3 id="pair-programming">Pair Programming
&lt;a class="heading-anchor" href="#pair-programming" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Pair Programming means all production software is developed by two people sitting at the same machine. The idea behind
this practice is that two brains and four eyes are better than one brain and two eyes. You effectively get a continuous
code review and quicker response to nagging problems that may stop one person dead in their tracks.&lt;/p>
&lt;p>Teams that have used pair programming have found that it improves quality and does not actually take twice as long
because they are able to work through problems quicker, and they stay more focused on the task at hand, thereby creating
less code to accomplish the same thing.&lt;/p>
&lt;p>Pair programmers:&lt;/p>
&lt;ul>
&lt;li>Keep each other on task.&lt;/li>
&lt;li>Brainstorm refinements to the system.&lt;/li>
&lt;li>Clarify ideas.&lt;/li>
&lt;li>Take initiative when their partner is stuck, thus lowering frustration.&lt;/li>
&lt;li>Hold each other accountable to the team’s practices.&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>Pair programming is a dialog between two people simultaneously programming (and analyzing and designing and testing)
and trying to program better.&lt;/p>
&lt;/blockquote>
&lt;p>Though, if you need privacy and time to work on an idea, go ahead and do it. We need both companionship and privacy.
Make sure to rotate pairs frequently and take frequent breaks, pairing can be tiring, but surely is rewarding.&lt;/p>
&lt;h3 id="stories">Stories
&lt;a class="heading-anchor" href="#stories" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Describe what the product should do in terms meaningful to customers and users. These stories are intended to be short
descriptions of things users want to be able to do with the product that can be used for planning and serve as reminders
for more detailed conversations when the team gets around to realizing that particular story.&lt;/p>
&lt;p>Give the stories a short title and a description. Write them on cards and put them on a wall that is often being passed.&lt;/p>
&lt;p>In XP stories are estimated extremely early, which gets the team thinking about how to get the largest return from the
tiny investment.&lt;/p>
&lt;h3 id="weekly-cycle">Weekly Cycle
&lt;a class="heading-anchor" href="#weekly-cycle" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>The Weekly Cycle is synonymous to an iteration. In the case of XP, the team meets on the first day of the week to
reflect on progress to date, the customer picks the stories they would like delivered in that week, and the team
determines how they will approach those stories.&lt;/p>
&lt;p>The intent behind the time boxed delivery period is to produce something to show to the customer for feedback.&lt;/p>
&lt;h3 id="ten-minute-build">Ten-Minute Build
&lt;a class="heading-anchor" href="#ten-minute-build" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>The goal with the Ten-Minute Build is to automatically build the whole system and run all of the tests in ten minutes.&lt;/p>
&lt;h3 id="continuous-integration">Continuous Integration
&lt;a class="heading-anchor" href="#continuous-integration" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Continuous Integration is a practice where code changes are immediately tested when they are added to a larger code
base. The benefit of this practice is you can catch and fix integration issues sooner.&lt;/p>
&lt;p>This practice requires some extra discipline and is highly dependent on Ten Minute Build and Test First Development.&lt;/p>
&lt;h3 id="test-first-programming">Test-First Programming
&lt;a class="heading-anchor" href="#test-first-programming" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;blockquote>
&lt;p>Write a failing automated test before changing any code.&lt;/p>
&lt;/blockquote>
&lt;p>The book mentions 4 problem Test-First Programming addresses at once:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Scope creep: It’s easy to get carried away programming and put in code “just in case.” By stating explicitly and
objectively what the program is supposed to do, you give yourself a focus for your coding. If you really want to put
that other code in, write another test after you’ve made this one work.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Coupling and cohesion: If it’s hard to write a test, it’s a signal that you have a design problem, not a testing
problem. Loosely coupled, highly cohesive code is easy to test.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Trust: It’s hard to trust the author of code that doesn’t work. By writing clean code that works and demonstrating
your intentions with automated tests, you give your teammates a reason to trust you.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Rhythm: It’s easy to get lost for hours when you are coding. When programming test-first, it’s clearer what to do
next: either write another test or make the broken test work. Soon this develops into a natural and efficient rhythm:
test, code, refactor, test, code, refactor.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h3 id="incremental-design">Incremental Design
&lt;a class="heading-anchor" href="#incremental-design" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;blockquote>
&lt;p>Invest in the design of the system every day.&lt;/p>
&lt;/blockquote>
&lt;p>You do a little bit of work up front to understand the proper breadth-wise perspective of the system design, and then
dive into the details of a particular aspect of that design when you deliver specific features.&lt;/p>
&lt;p>This approach reduces the cost of changes and allows you to make design decisions when necessary based on the most
current information available.&lt;/p>
&lt;hr />
&lt;h2 id="roles">Roles
&lt;a class="heading-anchor" href="#roles" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;p>Although XP specifies particular practices for your team to follow, it doesn’t really establish specific roles for the
people on your team.&lt;/p>
&lt;p>Depending on which source you read, there is either no guidance, or there is a description of how roles typically found
in more traditional projects behave on XP projects.&lt;/p>
&lt;h3 id="the-customer">The Customer
&lt;a class="heading-anchor" href="#the-customer" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>The Customer role is responsible for making all of the business decisions regarding the project including:&lt;/p>
&lt;p>The XP Customer is assumed to be a single person, however experience has shown that one person cannot adequately provide
all of the business related information about a project.&lt;/p>
&lt;h3 id="the-developer">The Developer
&lt;a class="heading-anchor" href="#the-developer" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Because XP does not have much need for role definition, everyone on the team (with the exception of the customer and a
couple of secondary roles listed below) is labeled a developer. Developers are responsible for realizing the stories
identified by the Customer.&lt;/p>
&lt;h3 id="the-tracker">The Tracker
&lt;a class="heading-anchor" href="#the-tracker" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>The main purpose of this role is to keep track of relevant metrics that the team feels necessary to track their progress
and to identify areas for improvement.&lt;/p>
&lt;h3 id="the-coach">The Coach
&lt;a class="heading-anchor" href="#the-coach" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>This is usually an outside consultant (or someone from elsewhere in your organization) who has used XP before and is
included in your team to help mentor the other team members on the XP Practices and to help your team maintain your
self-discipline.&lt;/p>
&lt;hr />
&lt;h4 id="what-is-xp-in-2-min">What is XP? (in 2 min)
&lt;a class="heading-anchor" href="#what-is-xp-in-2-min" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h4>
&lt;div style="position:relative;aspect-ratio:16/9;width:100%;">
&lt;iframe
src="https://www.youtube-nocookie.com/embed/hbFOwqYIOcU"
title="YouTube video"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
referrerpolicy="strict-origin-when-cross-origin"
style="position:absolute;inset:0;width:100%;height:100%;border:0;"
allowfullscreen>
&lt;/iframe>
&lt;/div>
&lt;h4 id="tech-talk-by-kent-beck-xp-20-years-later">Tech Talk by kent Beck: XP 20 years later
&lt;a class="heading-anchor" href="#tech-talk-by-kent-beck-xp-20-years-later" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h4>
&lt;div style="position:relative;aspect-ratio:16/9;width:100%;">
&lt;iframe
src="https://www.youtube-nocookie.com/embed/cGuTmOUdFbo"
title="YouTube video"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
referrerpolicy="strict-origin-when-cross-origin"
style="position:absolute;inset:0;width:100%;height:100%;border:0;"
allowfullscreen>
&lt;/iframe>
&lt;/div></content></entry><entry xml:lang="en"><title>Working Effectively with Legacy Code</title><subtitle>Start-to-finish strategies for working with large, untested legacy code bases</subtitle><category term="refactoring" scheme="https://chemaclass.com/tags/refactoring/" label="Refactoring"/><category term="testing" scheme="https://chemaclass.com/tags/testing/" label="Testing"/><category term="tdd" scheme="https://chemaclass.com/tags/tdd/" label="Tdd"/><category term="software-design" scheme="https://chemaclass.com/tags/software-design/" label="Software Design"/><published>2019-07-01T00:00:00+00:00</published><updated>2019-07-01T00:00:00+00:00</updated><author><name>
Michael Feathers</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/readings/working-effectively-with-legacy-code/"/><id>https://chemaclass.com/readings/working-effectively-with-legacy-code/</id><summary type="html">Michael Feathers presents practical techniques for adding tests to untested code, breaking dependencies, and safely refactoring large legacy systems without introducing bugs.</summary><content type="html">&lt;span id="continue-reading">&lt;/span>&lt;h2 id="what-is-legacy-code">What is legacy code?
&lt;a class="heading-anchor" href="#what-is-legacy-code" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;blockquote>
&lt;p>Legacy code is simply code without tests.&lt;/p>
&lt;/blockquote>
&lt;h3 id="benefits-of-tests">Benefits of tests
&lt;a class="heading-anchor" href="#benefits-of-tests" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>Behavior is central to understanding the benefits of testing:&lt;/p>
&lt;blockquote>
&lt;p>Behavior is the most important thing about software. It is what users depend on. Users like it when we add behavior (provided it is what they really wanted), but if we change or remove behavior they depend on (introduce bugs), they stop trusting us.&lt;/p>
&lt;/blockquote>
&lt;h3 id="how-to-get-tests-in-place-in-legacy-codebases">How to get tests in place in legacy codebases
&lt;a class="heading-anchor" href="#how-to-get-tests-in-place-in-legacy-codebases" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;p>When we change code, we should have tests in place. To put the tests in place, we often have to change code.&lt;/p>
&lt;p>The suggested approach:&lt;/p>
&lt;ol>
&lt;li>Identify change points.&lt;/li>
&lt;li>Find test points.&lt;/li>
&lt;li>Break dependencies.&lt;/li>
&lt;li>Write tests.&lt;/li>
&lt;li>Make changes and refactor.&lt;/li>
&lt;/ol>
&lt;p>Another useful term is a “&lt;strong>seam&lt;/strong>.” A seam, in this context, is “&lt;strong>a place where you can alter behavior in your program
without editing in that place&lt;/strong>”. The analogy is to a seam in clothing, the place where two parts are stitched together.
In software, &lt;strong>these places are generally places where there are well-defined interfaces&lt;/strong>. This can be leveraged to change
the implementation using techniques such as dependency injection or mocking interfaces in the case of writing tests.&lt;/p>
&lt;hr />
&lt;div style="position:relative;aspect-ratio:16/9;width:100%;">
&lt;iframe
src="https://www.youtube-nocookie.com/embed/wRtJRkRIa2s"
title="YouTube video"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
referrerpolicy="strict-origin-when-cross-origin"
style="position:absolute;inset:0;width:100%;height:100%;border:0;"
allowfullscreen>
&lt;/iframe>
&lt;/div></content></entry><entry xml:lang="en"><title>The Clean Coder</title><subtitle>A Code of Conduct for Professional Programmers</subtitle><category term="clean-code" scheme="https://chemaclass.com/tags/clean-code/" label="Clean Code"/><category term="career" scheme="https://chemaclass.com/tags/career/" label="Career"/><category term="tdd" scheme="https://chemaclass.com/tags/tdd/" label="Tdd"/><category term="communication" scheme="https://chemaclass.com/tags/communication/" label="Communication"/><published>2016-08-01T00:00:00+00:00</published><updated>2016-08-01T00:00:00+00:00</updated><author><name>
Robert C. Martin</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/readings/the-clean-coder/"/><id>https://chemaclass.com/readings/the-clean-coder/</id><summary type="html">Robert C. Martin's guide to professional behavior in software development, covering time management, pressure handling, TDD practices, and what it truly means to be a software craftsman.</summary><content type="html">&lt;p>Programmers who endure and succeed amidst swirling uncertainty and nonstop pressure share a common attribute: They care
deeply about the practice of creating software. They treat it as a craft. They are professionals.&lt;/p>
&lt;span id="continue-reading">&lt;/span>&lt;h3 id="readers-will-learn">Readers will learn
&lt;a class="heading-anchor" href="#readers-will-learn" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>What it means to behave as a true software craftsman&lt;/li>
&lt;li>How to deal with conflict, tight schedules, and unreasonable managers&lt;/li>
&lt;li>How to get into the flow of coding, and get past writer’s block&lt;/li>
&lt;li>How to handle unrelenting pressure and avoid burnout&lt;/li>
&lt;li>How to combine enduring attitudes with new development paradigms&lt;/li>
&lt;li>How to manage your time, and avoid blind alleys, marshes, bogs, and swamps&lt;/li>
&lt;li>How to foster environments where programmers and teams can thrive&lt;/li>
&lt;li>When to say &lt;strong>No&lt;/strong> and how to say it&lt;/li>
&lt;li>When to say &lt;strong>Yes&lt;/strong> and what yes really means&lt;/li>
&lt;/ul>
&lt;hr />
&lt;h2 id="summary">Summary
&lt;a class="heading-anchor" href="#summary" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;h3 id="chapter-1-professionalism">Chapter 1: Professionalism
&lt;a class="heading-anchor" href="#chapter-1-professionalism" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>Being a professional means taking full responsibility for one’s actions.&lt;/li>
&lt;li>First rule is not doing harm to the function nor the structure of the software.&lt;/li>
&lt;li>You will always make occasional mistakes, but you must learn from each.&lt;/li>
&lt;li>You should be certain about all code you release and firmly expect QA to find nothing wrong with it.
&lt;ul>
&lt;li>Test it and test it again.&lt;/li>
&lt;li>Automate your tests.&lt;/li>
&lt;li>Design your code to be easy to test.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>You should follow the Boy Scout rule and always leave a module a little cleaner than you found it so that it becomes
easier to change over time, not harder.&lt;/li>
&lt;li>Your career is &lt;strong>your responsibility&lt;/strong>, not your boss nor your employers.
&lt;ul>
&lt;li>Spending 20 hours a week beyond your normal work to improve your knowledge and skills.&lt;/li>
&lt;li>Read, experiment, practice (kata), talk to other, collaborate, look over the fence, mentor.&lt;/li>
&lt;li>It should be fun.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Also, know your domain, identify with your customer (no “us vs. them”, ever).&lt;/li>
&lt;/ul>
&lt;h3 id="chapter-2-saying-no">Chapter 2: Saying No
&lt;a class="heading-anchor" href="#chapter-2-saying-no" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>Professionals have the courage to say no to their managers.&lt;/li>
&lt;li>Managers and developers have roles that are often adversarial, because on the short term, their goals tend to
conflict.&lt;/li>
&lt;li>The higher the stakes, the more valuable a “no” becomes, and the harder to say.&lt;/li>
&lt;li>Good teams will successfully work towards a yes, but only a right yes, that will later work out in practice.&lt;/li>
&lt;/ul>
&lt;h3 id="chapter-3-saying-yes">Chapter 3: Saying Yes
&lt;a class="heading-anchor" href="#chapter-3-saying-yes" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>There are three parts to making a commitment:
&lt;ul>
&lt;li>You say you will do it&lt;/li>
&lt;li>You mean it&lt;/li>
&lt;li>You actually do it&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Your commitment must respect the limits of what you expect (based on your experience) you can and cannot do.
&lt;ul>
&lt;li>If you recognize you will probably not be able to meet a commitment, you need to raise a red flag immediately.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h3 id="chapter-4-coding">Chapter 4: Coding
&lt;a class="heading-anchor" href="#chapter-4-coding" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>Programming requires a level of focus that few other disciplines require.&lt;/li>
&lt;li>“The zone” (or “flow”) is not as good as people think: you will be locally productive, but will often lose the bigger
picture and possibly product not-so-good designs.&lt;/li>
&lt;li>Interruptions are bad distractions.
&lt;ul>
&lt;li>Pair programming is helpful to cope with them.&lt;/li>
&lt;li>TDD helps to make the pre-interruption context reproducible.
&lt;ul>
&lt;li>Minimize time spent debugging&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Coding is a &lt;strong>marathon&lt;/strong>, not a sprint, so conserve the energy and creativity.&lt;/li>
&lt;li>Leave when it’s time, even in the middle of something important.&lt;/li>
&lt;li>Continuously re-estimate your best/likely/worst completion time and speak up as soon as you recognize you will likely
be late.
&lt;ul>
&lt;li>Do not allow anyone to rush you.&lt;/li>
&lt;li>Use a proper definition of “done”, with sufficiently high quality requirements.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Programming is too hard for anyone, so get help and provide help to others, in particular (but not only) in mentoring
style.
&lt;ul>
&lt;li>Don’t be shy from asking.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h3 id="chapter-5-test-driven-development">Chapter 5: Test-Driven Development
&lt;a class="heading-anchor" href="#chapter-5-test-driven-development" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>&lt;a rel="external" href="https://en.wikipedia.org/wiki/Test-driven_development">TDD&lt;/a> is not a cure-all and is impractical or inappropriate in
some (rare) cases.&lt;/li>
&lt;li>TDD Cycle:
&lt;ol>
&lt;li>Add a test&lt;/li>
&lt;li>Run all tests. The new test should fail for expected reasons&lt;/li>
&lt;li>Write the simplest code that passes the new test&lt;/li>
&lt;li>All tests should now pass&lt;/li>
&lt;li>Refactor as needed&lt;/li>
&lt;li>Repeat&lt;/li>
&lt;/ol>
&lt;/li>
&lt;/ul>
&lt;h3 id="chapter-6-practicing">Chapter 6: Practicing
&lt;a class="heading-anchor" href="#chapter-6-practicing" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>A programming Kata is a precise set of choreographed keystrokes and mouse movements that simulates the solving of some
programming problem.
&lt;ul>
&lt;li>A Kata is about the process, not the solution.&lt;/li>
&lt;li>You aren’t solving the problem because you already know the solution.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h3 id="chapter-7-acceptance-testings">Chapter 7: Acceptance Testings
&lt;a class="heading-anchor" href="#chapter-7-acceptance-testings" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>Avoid garbage in, garbage out. Make sure you understand the requirements.
&lt;ul>
&lt;li>Creating this understanding means removing ambiguity.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>The best way to do this is defining acceptance tests:
&lt;ul>
&lt;li>All customer’s conditions need to be fulfilled by automated tests to prove the expected software behavior.&lt;/li>
&lt;li>Success of those tests constitutes the definition of “Done”.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Code implementation should start only when the tests are complete.&lt;/li>
&lt;li>Unlike unit tests (which are only for programmers), the audience of acceptance tests are both: business and
developers.&lt;/li>
&lt;li>Run all tests in a continuous integration and immediately fix any failures.&lt;/li>
&lt;/ul>
&lt;h3 id="chapter-8-test-strategies">Chapter 8: Test Strategies
&lt;a class="heading-anchor" href="#chapter-8-test-strategies" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>Consider QA part of the team. They act as specifiers: writing acceptance tests, including the failure cases and corner
cases, and perform exploratory testing.&lt;/li>
&lt;li>Testing pyramid:
&lt;ul>
&lt;li>Most tests are unit tests. By developer and for developers.&lt;/li>
&lt;li>Many tests are component or integration tests. By QA or Business assisted by Developers. For Business and
Developers.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h3 id="chapter-9-time-management">Chapter 9: Time management
&lt;a class="heading-anchor" href="#chapter-9-time-management" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>Management roles in software development requires good time management.&lt;/li>
&lt;li>Meeting are necessary but are also often huge time wasters, so avoid meeting that have no clear benefit &amp;lt;- this is a
professional obligation.&lt;/li>
&lt;li>Meeting must have an agenda and a clear goal.
&lt;ul>
&lt;li>Agile stand up meetings can be an efficient format.&lt;/li>
&lt;li>Iteration planning should take 5% of the iteration.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Concentration (focus) is a scarce resource.
&lt;ul>
&lt;li>Use it well when present and recharge with simpler tasks (meetings) and breaks in between.&lt;/li>
&lt;li>How to improve?
&lt;ul>
&lt;li>Sport.&lt;/li>
&lt;li>Creative input.&lt;/li>
&lt;li>Short breaks every 45 minutes.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h3 id="chapter-10-estimation">Chapter 10: Estimation
&lt;a class="heading-anchor" href="#chapter-10-estimation" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>Estimation is the source of most distrust between business people and developers because the latter provide estimate
which the former treats like commitments.
&lt;ul>
&lt;li>Both are insufficiently aware that the estimate really is a probability distribution, not a fixed number.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h3 id="chapter-11-pressure">Chapter 11: Pressure
&lt;a class="heading-anchor" href="#chapter-11-pressure" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>The professional developer is calm and decisive under pressure, adhering to his training and disciplines, knowing that
they are the best way to meet pressing deadlines and commitments.&lt;/li>
&lt;li>Avoid situations that cause pressure via:
&lt;ul>
&lt;li>make only commitments you can fulfill&lt;/li>
&lt;li>keep your code clean&lt;/li>
&lt;li>work in such a way that you need not change it when in crisis&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Don’t panic. Talk with your team. Don’t rush. Trust your disciplines.&lt;/li>
&lt;li>Offer to pair to others in crisis.&lt;/li>
&lt;/ul>
&lt;h3 id="chapter-12-collaboration">Chapter 12: Collaboration
&lt;a class="heading-anchor" href="#chapter-12-collaboration" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>Not all but most programmers like working alone. But we need to understand the goals of the surrounding people,
including business folks.
&lt;ul>
&lt;li>This requires &lt;strong>communication&lt;/strong>.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Likewise, within the development team: only collective code ownership and pairing produce a good level of
communication.
&lt;ul>
&lt;li>Programming is all about &lt;strong>communication&lt;/strong>.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h3 id="chapter-13-teams-and-projects">Chapter 13: Teams and Projects
&lt;a class="heading-anchor" href="#chapter-13-teams-and-projects" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>Teams need time (months) to gel, to really get to know each other and learn to truly work together.
&lt;ul>
&lt;li>Assigning fractional people to different projects is a bad idea, as is breaking up a good team at the end of a
project.&lt;/li>
&lt;li>Instead, assigning several projects to one team can work well.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h3 id="chapter-14-mentoring-apprenticeship-and-craftsmanship">Chapter 14: Mentoring, Apprenticeship and Craftsmanship
&lt;a class="heading-anchor" href="#chapter-14-mentoring-apprenticeship-and-craftsmanship" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>Young programmers need mentoring.
&lt;ul>
&lt;li>Mentoring can be implicit or explicit.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Given that we entrust software with all aspects of our lives, a reasonable period of training and supervised practice
would be appropriate.&lt;/li>
&lt;/ul>
&lt;hr />
&lt;p>In this lesson, Uncle Bob demonstrates the need to write a clean code and establishes the bases to achieve it,
being these bases of a social and scientific nature. Making it clear that the future of programming is based on an
ethical and polite code.&lt;/p>
&lt;div style="position:relative;aspect-ratio:16/9;width:100%;">
&lt;iframe
src="https://www.youtube-nocookie.com/embed/7EmboKQH8lM"
title="YouTube video"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
referrerpolicy="strict-origin-when-cross-origin"
style="position:absolute;inset:0;width:100%;height:100%;border:0;"
allowfullscreen>
&lt;/iframe>
&lt;/div>
&lt;hr />
&lt;p>In this second lesson, Uncle Bob teaches us the purpose of comments in the code, breaking the paradigm that commenting
is something “I have to do” for the simple fact that we mistakenly consider that commenting is a good practice. For
Uncle Bob, writing a comment is a sign of failure, since a good code must be able explain by itself: Fewer Comments =
Better Code.&lt;/p>
&lt;div style="position:relative;aspect-ratio:16/9;width:100%;">
&lt;iframe
src="https://www.youtube-nocookie.com/embed/2a_ytyt9sf8"
title="YouTube video"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
referrerpolicy="strict-origin-when-cross-origin"
style="position:absolute;inset:0;width:100%;height:100%;border:0;"
allowfullscreen>
&lt;/iframe>
&lt;/div>
&lt;hr />
&lt;p>In this third lesson, Uncle Bob focuses on raising awareness, given the need to increase the level of criteria in code
production. Pointing to the lack of preparation in most programmers, as one of the main reasons for the inefficiency in
software development today.&lt;/p>
&lt;div style="position:relative;aspect-ratio:16/9;width:100%;">
&lt;iframe
src="https://www.youtube-nocookie.com/embed/Qjywrq2gM8o"
title="YouTube video"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
referrerpolicy="strict-origin-when-cross-origin"
style="position:absolute;inset:0;width:100%;height:100%;border:0;"
allowfullscreen>
&lt;/iframe>
&lt;/div>
&lt;hr />
&lt;p>In this fourth lesson, Uncle Bob introduces us to a software development methodology oriented through testing. This is
the Test-Driven Development (TDD), a practice with a long learning curve, but with significant results to generate a
more robust, safer, more maintainable code and with greater development efficiency.&lt;/p>
&lt;div style="position:relative;aspect-ratio:16/9;width:100%;">
&lt;iframe
src="https://www.youtube-nocookie.com/embed/58jGpV2Cg50"
title="YouTube video"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
referrerpolicy="strict-origin-when-cross-origin"
style="position:absolute;inset:0;width:100%;height:100%;border:0;"
allowfullscreen>
&lt;/iframe>
&lt;/div></content></entry><entry xml:lang="en"><title>Clean Code</title><subtitle>A Handbook of Agile Software Craftsmanship</subtitle><category term="clean-code" scheme="https://chemaclass.com/tags/clean-code/" label="Clean Code"/><category term="software-design" scheme="https://chemaclass.com/tags/software-design/" label="Software Design"/><category term="testing" scheme="https://chemaclass.com/tags/testing/" label="Testing"/><category term="tdd" scheme="https://chemaclass.com/tags/tdd/" label="Tdd"/><category term="refactoring" scheme="https://chemaclass.com/tags/refactoring/" label="Refactoring"/><published>2016-05-01T00:00:00+00:00</published><updated>2016-05-01T00:00:00+00:00</updated><author><name>
Robert C. Martin</name></author><link rel="alternate" type="text/html" href="https://chemaclass.com/readings/clean-code/"/><id>https://chemaclass.com/readings/clean-code/</id><summary type="html">Even bad code can function. But if code isn't clean, it can bring a development organization to its knees. Every year, countless hours and significant resources are lost because of poorly written code. But it doesn't have to be that way.</summary><content type="html">&lt;p>Even bad code can function. But if code isn’t clean, it can bring a development organization to its knees. Every year,
countless hours and significant resources are lost because of poorly written code. But it doesn’t have to be that way.&lt;/p>
&lt;span id="continue-reading">&lt;/span>
&lt;hr />
&lt;h2 id="summary">Summary
&lt;a class="heading-anchor" href="#summary" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h2>
&lt;h3 id="chapter-1-what-is-clean-code">Chapter 1: What Is Clean Code?
&lt;a class="heading-anchor" href="#chapter-1-what-is-clean-code" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>The code can be measured with either “good” or “bad” in the code review or by how many minutes it takes you to talk
about it.&lt;/li>
&lt;li>A clean code should be elegant, efficient, readable, simple, without duplications, and well-written.&lt;/li>
&lt;li>You should add value to the business with your code.&lt;/li>
&lt;li>Clean code offers quality and understanding when we open the source file.&lt;/li>
&lt;li>It is necessary that your code is clean and readable for anyone to find and easily understand. Avoid wasting others’
time.&lt;/li>
&lt;/ul>
&lt;h3 id="chapter-2-meaningful-names">Chapter 2: Meaningful Names
&lt;a class="heading-anchor" href="#chapter-2-meaningful-names" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>Names of the classes, variables, and methods must be meaningful and clearly indicate what a method does or what an
attribute is.&lt;/li>
&lt;li>Create pronounceable names to facilitate communication.&lt;/li>
&lt;li>Avoid acronyms and avoid confusing names, which may bring anyone who reads the code to the wrong conclusions.&lt;/li>
&lt;li>Use names that reflect the system domain, the context, and the problems that must be solved.&lt;/li>
&lt;/ul>
&lt;h3 id="chapter-3-functions">Chapter 3: Functions
&lt;a class="heading-anchor" href="#chapter-3-functions" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>Methods should be easy to read and understand.&lt;/li>
&lt;li>Methods should convey its intention.&lt;/li>
&lt;li>Methods should be small.&lt;/li>
&lt;li>They must have up to 20 lines.&lt;/li>
&lt;li>Methods should only do one thing.&lt;/li>
&lt;li>You should use names with words that say what it really does.&lt;/li>
&lt;li>The optimal number of parameters of a method is zero, after one and two.&lt;/li>
&lt;li>Three should be avoided, but if you think it should be used, have a justification.&lt;/li>
&lt;li>&lt;code>Boolean&lt;/code> type as a parameter already states that it does more than one thing.&lt;/li>
&lt;li>Avoid duplication.&lt;/li>
&lt;/ul>
&lt;h3 id="chapter-4-comments">Chapter 4: Comments
&lt;a class="heading-anchor" href="#chapter-4-comments" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>One of the common reasons for comments is because the code is bad.&lt;/li>
&lt;li>If you’re thinking about writing a comment, then the code should be refactored.&lt;/li>
&lt;li>Comments do not save a bad code.&lt;/li>
&lt;li>Try to explain what the code causes happening.&lt;/li>
&lt;li>Comments can be useful when placed in certain places.&lt;/li>
&lt;li>Don’t explain your code with comments. Use informative vars/method names.&lt;/li>
&lt;li>Comments can be used to express the importance of certain points.&lt;/li>
&lt;li>Do not write comments with redundant, useless, or false information.&lt;/li>
&lt;li>They shouldn’t be used to indicate who changed or why, use versioning.&lt;/li>
&lt;li>Don’t comment code that will not be used. Remove it instead.&lt;/li>
&lt;/ul>
&lt;h3 id="chapter-5-formatting">Chapter 5: Formatting
&lt;a class="heading-anchor" href="#chapter-5-formatting" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>Formatting should indicate things of importance since it is a developer of communication form.&lt;/li>
&lt;li>A messy code is hard to read.&lt;/li>
&lt;li>The readability of the code will take effect on all the changes that will be made.&lt;/li>
&lt;li>Smaller classes are easier to understand.&lt;/li>
&lt;li>Set a limit of characters per line of code. For example 120.&lt;/li>
&lt;li>Try to keep more next related concepts vertically to create a code stream.&lt;/li>
&lt;li>Use spaces between operators, parameters, and commas.&lt;/li>
&lt;/ul>
&lt;h3 id="chapter-6-objects-and-data-structure">Chapter 6: Objects and Data Structure
&lt;a class="heading-anchor" href="#chapter-6-objects-and-data-structure" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>Follow the &lt;a rel="external" href="https://en.wikipedia.org/wiki/Law_of_Demeter">Law of Demeter&lt;/a>:
&lt;ul>
&lt;li>Each unit should have only limited knowledge about other units: only units “closely” related to the current unit.&lt;/li>
&lt;li>Each unit should only talk to its friends; don’t talk to strangers.&lt;/li>
&lt;li>Only talk to your immediate friends.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Do not make dumb objects.&lt;/li>
&lt;li>Objects hide the data abstraction and expose methods that operate the data.&lt;/li>
&lt;li>Data structures expose your data and do not have significant methods.&lt;/li>
&lt;/ul>
&lt;h3 id="chapter-7-error-handling">Chapter 7: Error Handling
&lt;a class="heading-anchor" href="#chapter-7-error-handling" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>Error handling should be planned carefully by all programmers.&lt;/li>
&lt;li>When wrong things occur, we have to get it to do the right things.&lt;/li>
&lt;li>Give preference to launching an exception than treating it just to hide.&lt;/li>
&lt;li>Create messages with information about the error.&lt;/li>
&lt;li>Mention that it failed. Where was this failure? If possible, mention why it failed.&lt;/li>
&lt;li>Look at separate business rules for errors and error handling.&lt;/li>
&lt;li>Avoid returning a &lt;code>NULL&lt;/code> in methods, preferably to return an empty object.&lt;/li>
&lt;li>Avoid passing &lt;code>NULL&lt;/code> to the methods; this can generate &lt;code>NullPointerExceptions&lt;/code>.&lt;/li>
&lt;/ul>
&lt;h3 id="chapter-8-boundary">Chapter 8: Boundary
&lt;a class="heading-anchor" href="#chapter-8-boundary" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>In third-party code, to avoid passing objects, APIs look forward in order to keep things in the same class.&lt;/li>
&lt;li>Perform tests on the API’s third party.&lt;/li>
&lt;li>Study the documentation and test the third API before you start using it.&lt;/li>
&lt;li>Check well the features you will use.&lt;/li>
&lt;/ul>
&lt;h3 id="chapter-9-unit-tests">Chapter 9: Unit Tests
&lt;a class="heading-anchor" href="#chapter-9-unit-tests" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>Make sure each piece of code is doing what you expect it to do.&lt;/li>
&lt;li>Follow the &lt;a rel="external" href="https://en.wikipedia.org/wiki/Test-driven_development">TDDs law&lt;/a>:
&lt;ul>
&lt;li>Don’t create code before you have a failing test.&lt;/li>
&lt;li>Don’t create more tests than necessary to fail.&lt;/li>
&lt;li>You cannot write more code than enough to pass the test that is failing.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Keep your test clean.&lt;/li>
&lt;li>The tests must undergo changes in the same way that the code.&lt;/li>
&lt;li>The dirtier the code, the more difficult test will be to maintain.&lt;/li>
&lt;li>Use the F.I.R.S.T rule for testing:
&lt;ul>
&lt;li>The test is fast-running.&lt;/li>
&lt;li>The tests are independent of others.&lt;/li>
&lt;li>The test is repeatable in various environments.&lt;/li>
&lt;li>The test is self-validating.&lt;/li>
&lt;li>The test is timely.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>The test is as important as the production code.&lt;/li>
&lt;/ul>
&lt;h3 id="chapter-10-classes">Chapter 10: Classes
&lt;a class="heading-anchor" href="#chapter-10-classes" title="Copy link" aria-label="Link to this section">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>By default, classes should start with the variables:
&lt;ul>
&lt;li>Static and constants public.&lt;/li>
&lt;li>Static and variable private.&lt;/li>
&lt;li>Instances and variables privates.&lt;/li>
&lt;li>Soon after comes the functions.&lt;/li>
&lt;li>The class name should represent its responsibility.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>The class must have only &lt;a rel="external" href="https://en.wikipedia.org/wiki/Single-responsibility_principle">one responsibility&lt;/a>: one reason to change.&lt;/li>
&lt;li>You should try to make a brief description of the class.&lt;/li>
&lt;li>The methods should be small and one responsibility.&lt;/li>
&lt;/ul>
&lt;hr />
&lt;p>This interview is based on Uncle Bob’s book “Clean Code”. They cover some existing guides that can help you become a
better programmer and explore how books and current trends are shaping the software landscape.&lt;/p>
&lt;div style="position:relative;aspect-ratio:16/9;width:100%;">
&lt;iframe
src="https://www.youtube-nocookie.com/embed/QnmRpHFoYLk"
title="YouTube video"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
referrerpolicy="strict-origin-when-cross-origin"
style="position:absolute;inset:0;width:100%;height:100%;border:0;"
allowfullscreen>
&lt;/iframe>
&lt;/div></content></entry></feed>