<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: marvinav</title>
    <description>The latest articles on DEV Community by marvinav (@marvinav).</description>
    <link>https://dev.to/marvinav</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F674566%2Ff6df16fa-a0fc-44cc-b0bb-7e37c5583e7d.png</url>
      <title>DEV Community: marvinav</title>
      <link>https://dev.to/marvinav</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/marvinav"/>
    <language>en</language>
    <item>
      <title>Screenshot testing using storybook: real browser, fast performance, less visual regressions</title>
      <dc:creator>marvinav</dc:creator>
      <pubDate>Sat, 29 Mar 2025 07:49:31 +0000</pubDate>
      <link>https://dev.to/marvinav/screenshot-testing-gotta-catch-em-all-3123</link>
      <guid>https://dev.to/marvinav/screenshot-testing-gotta-catch-em-all-3123</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;When developing medium and large applications, UI/UX testing becomes a challenge. To verify the design and form interactions, we often need to understand the entire business flow, like how to navigate from Sign In Form to Add PayPal payment details form.&lt;br&gt;
This frequently requires:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creating test users&lt;/li&gt;
&lt;li&gt;Configuring necessary permissions&lt;/li&gt;
&lt;li&gt;Populating the database with test data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx8rgs4nwi3xjtzjg39w8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx8rgs4nwi3xjtzjg39w8.png" alt="Image description" width="500" height="375"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In such conditions, design validation becomes a struggle for developers, designers, and project managers.&lt;/p&gt;
&lt;h2&gt;
  
  
  Decouple UI/UX Testing from the Backend
&lt;/h2&gt;

&lt;p&gt;I believe that UI and UX validation should be independent from the backend. There is no reason to understand the entire business process just to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open User Profile view;&lt;/li&gt;
&lt;li&gt;Verify that the save button is enabled only after valid input;&lt;/li&gt;
&lt;li&gt;Ensure error messages appear appropriately when invalid data is entered.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  How to Achieve This?
&lt;/h3&gt;

&lt;p&gt;The only solution is to develop custom dev tools at least that:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Mock API calls&lt;/li&gt;
&lt;li&gt;Modify application stores&lt;/li&gt;
&lt;li&gt;Enable quick navigation within the UI&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This allows:&lt;br&gt;
✔️ Rapid validation of new frontend features;&lt;br&gt;
✔️ UI/UX testing without backend dependencies;&lt;br&gt;
✔️ Comparing current designs with previous versions.&lt;/p&gt;
&lt;h2&gt;
  
  
  Presets, dynamically change backend response, navigate between views.
&lt;/h2&gt;

&lt;p&gt;With dev tools, the desire to automate visual regression testing comes to mind. This leads us to the next topic: screenshot testing. Screenshot testing is the name for the assertion, not the type of testing. Screenshot testing could be e2e (for example playwright or selenium support screenshot snapshots), or unit tests.&lt;br&gt;
However E2E is slow, moreover they require a lot of business knowledge and sometimes infrastructure knowledge from developers. And do we really want to run the e2e test after changing the button padding? I don’t think so. The front-end unit test should care about consistency of design after changing the button padding. But true is&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;FRONTEND TESTS DON’T CARE ABOUT STYLES AT ALL&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It doesn’t make any sense for me, because even if it is just a small padding, it could create such a mess. Why do frontend developers ignore that? That is how I was working:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;testing-library - utils for testing React&lt;/li&gt;
&lt;li&gt;jest for running test&lt;/li&gt;
&lt;li&gt;node - javascript environment&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The problem in such an approach is: I don’t see the browser in the list. Where are we testing frontend units? Inside the virtual js-dom, it even doesn’t have 100% compatibility with the Browser DOM. Application behavior heavily depends on the device and environment:&lt;br&gt;
📱 Android, iOS&lt;br&gt;
💻 MacBook, Windows, Linux&lt;br&gt;
🌐 Chrome, Safari (even browser versions affect performance!)&lt;br&gt;
And here we are, frontend developers, who believe that js-dom inside nodejs runtime is a good idea to run tests.&lt;br&gt;
After discovering of the screenshot tests, I stopped testing UI unit test that are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ensuring DOM elements are rendered.&lt;/li&gt;
&lt;li&gt;Verifying the presence of a

&lt;code&gt;&amp;lt;div id="test"&amp;gt;&lt;/code&gt;

, or any other tests related to rendering, view or styles.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, unit testing with jest/node is still essential for logic independent from rendering. This is why separating view from model and state is crucial! But testing frontend view without styles or Browser APIs is like tasting a cake by only reading the recipe.&lt;/p&gt;
&lt;h2&gt;
  
  
  Environment
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Storybook
&lt;/h3&gt;

&lt;p&gt;Devtools for quickly navigating around UI components or pages is not something I created. Actually, it’s a pretty old issue which, in my opinion, has been solved by Storybook.js. What it could do now is quite impressive, and I only used like 25% of all Storybook features. Storybook is incorporated inside the frontend repository, and it has direct access to all UI components and code, but it doesn’t leave a trace in code. It’s like a jest unit test, but with different name extension:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;Login.test.tsx&lt;/code&gt; → &lt;code&gt;Login.story.tsx&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You could write stories as just plain stupid components, or you could make an actual story: full flow of some user activity. For more details on what is a storybook, you could check the official storybook page.&lt;br&gt;
Storybook showcase I like: &lt;a href="https://react95.github.io/React95/?path=/story/all--all" rel="noopener noreferrer"&gt;React95&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Docker
&lt;/h3&gt;

&lt;p&gt;Docker needs for several reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Minimal requirements to run screenshot test, just have docker installed&lt;/li&gt;
&lt;li&gt;Make you dev setup platform agnostic&lt;/li&gt;
&lt;li&gt;Chrome browser image (to have the same version of chrome across all developers and env)&lt;/li&gt;
&lt;li&gt;DPI and other OS setup/configuration affects the screenshots.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Loki
&lt;/h3&gt;

&lt;p&gt;Bunch of scripts for starting chrome, getting a list of stories, making screenshots and comparing them with references.&lt;br&gt;
Below you could find the example configuration for loki. It shows that you could run tests on chrome in laptop or mobile emulator (not a real mobile emulator, but the one in desktop devtools), and ios, android (never tested).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"loki"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"chromeSelector"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"#my-decorator &amp;gt; *"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"configurations"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"chrome.laptop"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"target"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"chrome.app"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"width"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1366&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"height"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;768&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"chrome.iphone7"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"target"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"chrome.docker"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"preset"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"iPhone 7"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"chrome.a4"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"target"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"chrome.aws-lambda"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"preset"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"A4 Paper"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"ios"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"target"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ios.simulator"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"android"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"target"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"android.emulator"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Loki stores screenshots in folder .loki:&lt;/p&gt;

&lt;h3&gt;
  
  
  ./loki/reference
&lt;/h3&gt;

&lt;p&gt;Screenshots in this folder are references for loki, they are gold standard. When loki runs a test, it compares the screenshot from this folder with the current test screenshot.&lt;/p&gt;

&lt;h3&gt;
  
  
  ./loki/current
&lt;/h3&gt;

&lt;p&gt;Screenshots in this folder are the screenshots from the latest run tests. Using them you could check the style, design and state of your current working tree.&lt;/p&gt;

&lt;h3&gt;
  
  
  ./loki/difference
&lt;/h3&gt;

&lt;p&gt;This folder contains an image diff between screenshots from current and reference.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to write a screenshot test
&lt;/h2&gt;

&lt;p&gt;1) Write a react component&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./button.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;ButtonProps&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="cm"&gt;/** Is this the principal call to action on the page? */&lt;/span&gt;
  &lt;span class="nl"&gt;primary&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="cm"&gt;/** What background color to use */&lt;/span&gt;
  &lt;span class="nl"&gt;backgroundColor&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="cm"&gt;/** How large should the button be? */&lt;/span&gt;
  &lt;span class="nl"&gt;size&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;small&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;medium&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;large&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="cm"&gt;/** Button contents */&lt;/span&gt;
  &lt;span class="nl"&gt;label&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="cm"&gt;/** Optional click handler */&lt;/span&gt;
  &lt;span class="nl"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="cm"&gt;/** Primary UI component for user interaction */&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="nx"&gt;primary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;medium&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;backgroundColor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;
&lt;span class="p"&gt;}:&lt;/span&gt; &lt;span class="nx"&gt;ButtonProps&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;primary&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;storybook-button--primary&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;storybook-button--secondary&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt;
      &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;storybook-button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`storybook-button--&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;backgroundColor&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2) Write a story for this component. It’s really easy. All file is basically story configuration&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Meta&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;StoryObj&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@storybook/react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@storybook/test&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./Button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;meta&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Example/Button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;parameters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout&lt;/span&gt;
    &lt;span class="na"&gt;layout&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;centered&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="c1"&gt;// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs&lt;/span&gt;
  &lt;span class="na"&gt;tags&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;autodocs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="c1"&gt;// More on argTypes: https://storybook.js.org/docs/api/argtypes&lt;/span&gt;
  &lt;span class="na"&gt;argTypes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;backgroundColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;control&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;color&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="c1"&gt;// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args&lt;/span&gt;
  &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;satisfies&lt;/span&gt; &lt;span class="nx"&gt;Meta&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Story&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;StoryObj&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;meta&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Primary&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Story&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;primary&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;label&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3) Build &lt;code&gt;storybook&lt;/code&gt; (good for CI/CD or one-time run) or run &lt;code&gt;storybook&lt;/code&gt; server (option for HMR to speed up development)&lt;br&gt;
4) Run &lt;code&gt;loki&lt;/code&gt; to create a reference screenshot&lt;br&gt;
From this moment, if something will change the design (also UX) of the button, loki will let you know with a FAILED test.&lt;/p&gt;
&lt;h2&gt;
  
  
  Rules to write stories
&lt;/h2&gt;

&lt;p&gt;Best story is a story isolated from the backend. The best way of thinking about a story is a unit test.&lt;br&gt;
Isolate stories from each other. It’s a unit test, the same story should produce the same output every time. It means avoid SIDE EFFECTS, avoid GLOBAL STORE.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Component is a function. Story is a function. Even OOP languages under hood are functions (all languages send instructions to CPU, not a Class Animal, but the instruction CPU is required to perform). Our life is the list of functions. Everything is a function. That is why it’s important to remember The Pure Function Rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the function return values are identical for identical arguments (no variation with local static variables, non-local variables, mutable reference arguments or input streams, i.e., referential transparency)&lt;/li&gt;
&lt;li&gt;the function has no side effects (no mutation of local static variables, non-local variables, mutable reference arguments or input/output streams).&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Screenshot unit tests are fast (faster then classical e2e tests), they are informative (you could see we current state of ui), they are useful (you are not mocking browser environment in node runtimer). From my own experience two hundreds screenshot tests run in &lt;code&gt;2min 30s&lt;/code&gt; on machine with &lt;code&gt;1gb RAM&lt;/code&gt; and &lt;code&gt;2 CPU&lt;/code&gt;.&lt;br&gt;
Lets consider that you update button style and want to merge it in main branch. In this case you need:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run &lt;code&gt;loki tests&lt;/code&gt; and approve new screenshots&lt;/li&gt;
&lt;li&gt;Add new screenshots to commit and create a PR&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Goog thing about remote gits (gitlab, github, bitbucket) is all of them supports diff of images. You could check this PR in &lt;a href="https://github.com/marvinav/demo-screenshots/pull/1/files" rel="noopener noreferrer"&gt;demo-screenshots&lt;/a&gt; repository and check how it's cool! You have options to compare old and new button story in three modes:&lt;/p&gt;
&lt;h4&gt;
  
  
  Side-by-side
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq3xde099f3l26jhq99df.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq3xde099f3l26jhq99df.png" alt="Side-by-side" width="536" height="272"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Swipe
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe2ritkt76oyyiarbu88n.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe2ritkt76oyyiarbu88n.gif" alt="Swipe" width="536" height="272"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Blend mode
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqj9jffl6q8co3pf0vsxn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqj9jffl6q8co3pf0vsxn.png" alt="Blend-mode" width="536" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the next part I will write you in details how to integrate loki in development workflow and which options you have to store your screenshots in your repo (&lt;code&gt;git&lt;/code&gt;, &lt;code&gt;git lfs&lt;/code&gt;, &lt;code&gt;parallel repository&lt;/code&gt;).&lt;/p&gt;
&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;1) &lt;a href="https://storybook.js.org/" rel="noopener noreferrer"&gt;Storybook&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2) &lt;a href="https://storybook.js.org/docs/writing-tests/visual-testing" rel="noopener noreferrer"&gt;Visual tests by Storybook (Chromatic)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Premium and cloud solution for screenshot testing. Basically, we &lt;br&gt;
 replicate it itself, but on our own.&lt;/p&gt;

&lt;p&gt;3) &lt;a href="https://loki.js.org/" rel="noopener noreferrer"&gt;Loki&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Basically a driver to run a storybook and make a screenshots. It is not so big, and &lt;code&gt;storybook/chrome&lt;/code&gt; interface is pretty stable, so I didn’t have unsolved problem in about last two years.&lt;/p&gt;

&lt;p&gt;4) &lt;a href="https://github.com/marvinav/demo-screenshots" rel="noopener noreferrer"&gt;Demo screenshot test repo&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cp&lt;/span&gt; .config/.env.example .config/.env.development
&lt;span class="nb"&gt;cp&lt;/span&gt; .config/.makerc.example .config/.makerc
make run &lt;span class="nv"&gt;SERVICE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;loki
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>typescript</category>
      <category>testing</category>
      <category>qa</category>
    </item>
    <item>
      <title>Fantastic Bugs and Where to Find Them</title>
      <dc:creator>marvinav</dc:creator>
      <pubDate>Tue, 18 Jun 2024 10:50:19 +0000</pubDate>
      <link>https://dev.to/marvinav/fantastic-bugs-and-where-to-find-them-2d10</link>
      <guid>https://dev.to/marvinav/fantastic-bugs-and-where-to-find-them-2d10</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Welcome back to our magical journey through the land of software bugs. If you missed &lt;a href="https://dev.to/marvinav/what-does-the-bugs-mean-14k1"&gt;the previous part&lt;/a&gt;, where we deciphered the enigmatic signs of bugs, fret not. This chapter will delve deeper into the mystical sources of these bugs and reveal the charms and spells needed to ward them off.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bugs living in code
&lt;/h2&gt;

&lt;p&gt;In the enchanted world of software development, there exists a hidden realm where bugs lurk like mischievous pixies. Much like the infamous Cornish Pixies released by Gilderoy Lockhart, these bugs wreak havoc in the most unexpected ways, causing chaos in codebases instead of classrooms. Welcome, dear reader, to a magical exploration of the dark arts of debugging, where we'll uncover the curious creatures known as mistype bugs, logical bugs, misusing bugs, and the ever-elusive integration bugs. Grab your wand (or, in this case, your keyboard) and prepare for a journey through the enchanted corridors of coding mishaps, where every spell cast (or line of code written) can lead to unexpected enchantments—or disasters.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mistype bugs
&lt;/h3&gt;

&lt;p&gt;Mistype bugs are typically not dependent on the developer's experience level. They tend to be more a function of company culture than any one person's skill. Common contributing factors are poor code review, no linters in CI/CD pipelines, few unit tests, and tight deadlines. Mistype bugs can range from simple typographical errors to more subtle mistake types that even avoid static code analysis tools. And to give you a personal example: I mixed in the letter 'c' from Cyrillic (&lt;strong&gt;UTF16 0441&lt;/strong&gt;) with the letter 'c' (&lt;strong&gt;UTF16 0063&lt;/strong&gt;) in the name of the endpoint. The name for the endpoint was &lt;code&gt;createPhase&lt;/code&gt; with the Russian 'c' at the start. Deployment of this bug led to three web services failing.&lt;br&gt;&lt;br&gt;
Mistype bugs can result in various problems within an application: infinite loops, out-of-memory problems, security hazards, and program freezes. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCounter&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setCounter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt; &lt;span class="c1"&gt;// If you forgot the second parameter, the empty array, as a dependency. It will be trapped in rendering an infinite cycle of increasing the counter&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Logical bugs
&lt;/h3&gt;

&lt;p&gt;Logical Bugs are the ones that live inside the code logic. They occur when the code does not work as expected, even though it is syntactically correct. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;calculateSum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setResult&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setResult&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;calculateSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Logical error: '2' is a string and causes the output to be combined&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, the cause for logical error is that the function calculated should add two numbers, but one of the arguments is a &lt;code&gt;string&lt;/code&gt;. This leads to string concatenation instead of numerical addition hence the result it gives is something that is not expected.&lt;/p&gt;

&lt;h3&gt;
  
  
  Misusing bugs
&lt;/h3&gt;

&lt;p&gt;Misusing bugs occur when a library or infrastructure or some language feature is wrongly used. Those bugs occur because the developer does not know the right way to use the tool and thus gets something wrong or some mistake in the code. These misconceptions can generally result in significant issues regarding the functionality of the application and its performance. Take, for instance, the following misuse of the &lt;code&gt;useEffect&lt;/code&gt; hook in React:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;estate &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://API.example.com/data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="c1"&gt;// Misuse: Including 'data' as a dependency leads to an infinite loop of fetching data&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Loading.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, the dependencies for &lt;code&gt;useEffect&lt;/code&gt; are being misused, making it result in an infinite loop. The &lt;code&gt;fetch&lt;/code&gt; operation is called again on every update of &lt;code&gt;data&lt;/code&gt;, hence leading to an infinite re-fetch operation and can be a performance nightmare.&lt;/p&gt;

&lt;p&gt;Misusing &lt;code&gt;debounce&lt;/code&gt; from lodash:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lodash&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleResize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;debounce&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Window resized&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;resize&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleResize&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Forgetting to remove the event listener on component unmount&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Integration bugs
&lt;/h3&gt;

&lt;p&gt;System-level integration bugs occur mainly when the interaction of two or more units of code written by different developers fails to interact correctly with one another. Inconsistencies or incompatibilities between the components often lead to these bugs in many situations. They are complex to find and repair because developers need to look at more significant chunks of code, which can be lengthy to replicate. For instance, consider the following scenario of an integration problem between a frontend React app and a backend API:&lt;/p&gt;

&lt;h4&gt;
  
  
  Example 1: Mismatched API Contract
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Frontend: React component expecting data in a specific format&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fetchUserData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/user&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nf"&gt;setUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Expects the API response to having a 'user' field&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="c1"&gt;// Backend: Express route sending data in a different format&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/user,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;userData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John Doe,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt; &lt;span class="c1"&gt;// Sends 'userData' instead of 'user'&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the frontend expects the API response to having a &lt;code&gt;user&lt;/code&gt; field, but the backend sends a &lt;code&gt;userData&lt;/code&gt; field. This then causes integration problems, leading to failure of the frontend in the correct processing of data.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example 2: Version Incompatibility
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Frontend: Using an old version of a shared library&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;format&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;shared-library@1.0.0&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;formattedDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Uses old formatting function&lt;/span&gt;

&lt;span class="c1"&gt;// Backend: Updated to use a new version of the shared library&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;format&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;shared-library@2.0.0&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;formatted&lt;/span&gt; &lt;span class="nx"&gt;date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;YYYY-MM-DD&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// New formatting function requires an additional parameter&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the frontend and backend are two different environments working with the same shared library, but in this case with versions not compatible with each other. Because the frontend relies on an older version of the formatting function, it will break when working with the backend, which has the updated version of the library.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bugs created by business
&lt;/h2&gt;

&lt;p&gt;The incantations of business requirements often summon unexpected creatures into our codebase. Much like a misfired spell from a novice wizard, these bugs emerge from the foggy misunderstandings between developers and the business side of things. Gather around, dear reader, as we delve into the world of business-induced bugs—those mischievous gremlins that sneak past the boundaries of specifications, twist the logic of business rules, and conjure unnecessary complexities.&lt;/p&gt;

&lt;h3&gt;
  
  
  Out of Bound
&lt;/h3&gt;

&lt;p&gt;Features and functionalities may go past or deviate from the specified requirements or intended use cases. The error might have occurred because of miscommunication or misconception in the first place between business developers and users. Implementation usually happens in features that are not required that are not accurately defined, or that are outside the project's scope. This may lead to resource waste, increased complexity, and potential issues in another part of the system.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example 1: Unnecessary Features
&lt;/h4&gt;

&lt;p&gt;A project requirement calls for a simple user registration process. A developer goes ahead to implement a multi-step registration that is meant to integrate with social media and additional verification steps because they misunderstood the requirements. It went out of scope, unnecessarily added complexity, and possibly more points of failure.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example 2: Misinterpreted Requirement
&lt;/h4&gt;

&lt;p&gt;The requirement is that users should receive email notifications for critical updates. A developer perceives these as notifications for every minor change, and the end users get bombarded with irrelevant emails, hence missing out on crucial updates.&lt;/p&gt;

&lt;h3&gt;
  
  
  Business Logical Bugs
&lt;/h3&gt;

&lt;p&gt;Business logical bugs arise when the implemented logic does not align with the business rules, requirements, or use cases. These bugs usually arise from an improper or partial understanding of business logic, leading to features whose functionality does not serve the intended purpose, or they misbehave under certain conditions. Such bugs may have terrible effects on a system's functionalities and operability.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example: Application of Discount in the Wrong Manner
&lt;/h4&gt;

&lt;p&gt;An e-commerce website has a business rule that declares that a 10% discount applies on orders over $100. Developers implemented this logic, but after new feature was deployed product owner seen that discount applies for order with the price after tax applied for it. This case wasn't clarified in requirements, and e-store owner spent more money on the promo campaign than it wanted. &lt;/p&gt;

&lt;h2&gt;
  
  
  Reducing the Number of Bugs
&lt;/h2&gt;

&lt;p&gt;Bugs, after all, are an inevitable part of software development. Still, their frequency and impact can be significantly reduced through best practices incorporated throughout workflow processes, code development, and business communication. A brief guide is given below.&lt;/p&gt;

&lt;h3&gt;
  
  
  Workflow Process
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Implement Project Management Methodologies&lt;/strong&gt;: For example agile methodologies have made it easier to do iterative development with continuous feedback and adaptive planning. This way, you can address pitfalls early in the development phase.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Continuous Integration/Continuous Deployment (CI/CD)&lt;/strong&gt;: Automated integration and deployment processes further ensure that any change to code keeps being validated and integrated, with a reduction in the chances of integration bugs and maintaining builds in a stable state.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Code Reviews&lt;/strong&gt;: This is a means of correcting mistakes that may be overlooked. Multiple pairs of eyes on your code can easily catch potential issues earlier and improve the general quality of the code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Automated Testing&lt;/strong&gt;: Unit, integration, and end-to-end tests as part of the CI/CD pipeline detect bugs at various levels of the development process.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Code Development Process
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Adopt Coding Standards and Guidelines&lt;/strong&gt;: Having coding standards and guidelines ensures that code is uniform, readable, and maintainable and that one can quickly identify and fix bugs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Static Code Analysis Tools&lt;/strong&gt;: Utilize tools such as ESLint, SonarQube, and Pylint, among others, to check the source code for likely issues: errors, code smells, and security vulnerabilities that a developer has to take into account beforehand.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Unit Test Writing&lt;/strong&gt;: Ensure that all test cases are written to find bugs on-time—more of the logic and mistyped bugs. Try to attain a high percentage of coverage with meaningful test cases.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Business Communication Process
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Clear Requirement Gathering&lt;/strong&gt;: Thorough and precise requirement gathering from stakeholders is critical. Arrange regular meetings with stakeholders so the development team is well-versed with business needs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Maintain a Well-Defined Glossary&lt;/strong&gt;: Involvement in creating and maintaining a glossary will ensure that team members have a common understanding of central concepts and terms. Thus, it will minimize the possibility of miscommunication.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Regular Feedback Loops&lt;/strong&gt;: Ensure that your development team has set up regular feedback loops with the stakeholders. This ensures that the project work is coherent with the business objective; thereby, any deviation may be checked promptly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;User Acceptance Testing (UAT)&lt;/strong&gt;: Engage users in testing the system to ensure the software meets their needs and expectations. Business logical bugs are not likely to be detected by developers; UAT is an effective way of identifying these errors.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Minimizing the number of bugs is an exercise in several dimensions, calling for perfection in all phases of software development. Best practices in workflow processes, along with the rigorous development of code and intensive communication of business issues, ensure a significant reduction in the number of bugs that crop up; this ultimately results in more reliable and robust software.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>testing</category>
      <category>qa</category>
      <category>bug</category>
    </item>
    <item>
      <title>What do the bugs mean?</title>
      <dc:creator>marvinav</dc:creator>
      <pubDate>Fri, 31 May 2024 09:05:53 +0000</pubDate>
      <link>https://dev.to/marvinav/what-does-the-bugs-mean-14k1</link>
      <guid>https://dev.to/marvinav/what-does-the-bugs-mean-14k1</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Bugs are often defined as the resulting undesired behavior—coming from the developer's mistake—in the code. Bugs are, of course, a very human-made thing. This article contextualizes the entire historical background around the word "bug," from Thomas Edison to the famous incident with a moth by Grace Hopper. It goes even further to speak of the significant consequences of software errors: economic losses, and critical failures within various industries. This serves to sharpen the point that human errors in software development should be tested for these consequences to be reduced.&lt;/p&gt;

&lt;h2&gt;
  
  
  The origin of termin
&lt;/h2&gt;

&lt;p&gt;The simplest answer to this question most common amongst developers is &lt;em&gt;‘bug is some undesired behavior caused by mistake in the code’&lt;/em&gt;. In general, this is a right answer that does not conflict with the true meaning of bug definition. But let’s look at how dictionaries define the bug.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Webster&lt;/strong&gt;: an unexpected defect, fault, flaw, or imperfection.&lt;br&gt;
&lt;strong&gt;Cambridge&lt;/strong&gt;: a mistake or problem in a computer program.&lt;br&gt;
&lt;strong&gt;Oxford&lt;/strong&gt;: with the sense ‘of or relating to errors or other causes of malfunction in a computer program’.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;However, those definitions do not highlight a very important detail that the bug is always caused by &lt;strong&gt;humans&lt;/strong&gt;. For instance, if a user splits a coffee on his laptop and it stops working - this is not a bug. However, if the laptop stops working, because voltage regulator modules send 2 V on cpu instead of 1.4 V - this is the bug. With keeping this in the mind let's expand the definition of the bug:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A bug is a flaw, failure, error, or fault in computer software or system, &lt;strong&gt;caused by humans&lt;/strong&gt;, that leads to unexpected or incorrect results,  or to behave in unintended ways.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I don't just want to draw attention to the human factor for no reason, but because in the next articles we will see that all ways to reduce the number of bugs should be aimed precisely at combating the human factor. But for now, let's trace the history of the bug.&lt;br&gt;
In the IT, there is an opinion that the concept of a bug started to be used after a real insect got stuck in the computer relay.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In 1946, when &lt;em&gt;Hopper&lt;/em&gt; was released from active duty, she joined the Harvard Faculty at the Computation Laboratory where she continued her work on the &lt;em&gt;Mark II&lt;/em&gt; and &lt;em&gt;Mark III&lt;/em&gt;. She traced an error in the &lt;em&gt;Mark II&lt;/em&gt; to a moth trapped in a relay, coining the term bug. This bug was carefully removed and taped to the log book. Stemming from the first bug, today we call errors or glitch's in a program a bug.&lt;br&gt;&lt;br&gt;
&lt;em&gt;"Danis, Sharron Ann: "Rear Admiral Grace Murray Hopper"". ei.cs.vt.edu. February 16, 1997. Retrieved January 31, 2010.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DGEtKD3K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://shorturl.at/Abj8S" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DGEtKD3K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://shorturl.at/Abj8S" alt="Photo of the origin entry log in journal with the taped moth" width="800" height="633"&gt;&lt;/a&gt;&lt;br&gt;
Picture 1 - Photo of the origin entry log in journal with the taped moth.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Disclaimer&lt;/strong&gt;. I want to note in advance that a good historical analysis was done by &lt;em&gt;Peggy A. Kidwell&lt;/em&gt;, and my favorite work is the article 'Stalking the Elusive Computer Bug' published in 1998 in the IEEE Annals of the History of Computing. If you are interested in delving deeper into this issue, I recommend referring to this article, as well as to the works of his. Below, I will provide only a brief overview of this article with some additional illustrations.&lt;/p&gt;

&lt;p&gt;A funny fact, but in the 1945 edition of the Oxford dictionary, you can find a definition for "&lt;strong&gt;debugging&lt;/strong&gt;," but not for "&lt;strong&gt;bug&lt;/strong&gt;." What does all this mean? The story about the moth is essentially true, however, the entry in the journal dates back to 1947, not 1946. So, in the early days of programming, among Harvard staff, the term "&lt;strong&gt;bugs&lt;/strong&gt;" was used before the story with the Mark computer. It turns out they adapted the terms "&lt;strong&gt;bug&lt;/strong&gt;," "&lt;strong&gt;debug&lt;/strong&gt;," and "&lt;strong&gt;debugging&lt;/strong&gt;" from technical slang prevalent in the USA.&lt;/p&gt;

&lt;p&gt;The word "&lt;strong&gt;bug&lt;/strong&gt;" and its relation to technology, or more particularly to computers, in reality, dates back to the time of Thomas Edison. He wrote the first documented use of the term "&lt;strong&gt;bug&lt;/strong&gt;" in a letter describing problems he is having with his phonograph:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"It has been just so in all of my inventions. The first step is an intuition—and comes with a burst, then difficulties arise—this thing gives out and then that—'Bugs'—as such little faults and difficulties are called."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;These problems are the kinds one of the U.S. engineers had long held to have been called about quite a while ago. This became popular because the term is short, and means the flaw is small and manageable. This conceptual history of the terminology is well-traced in sources ranging from dictionaries to anecdotes.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;1924&lt;/strong&gt;: In a comic strip from a 1924 telephone industry journal, a naive character learns that a man works as a "bug hunter" and gives him a backscratcher. The man explains that "bug hunter" is just a nickname for a repairman.    &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1931&lt;/strong&gt;: The first mechanical pinball game, Baffle Ball, was marketed as being "free of bugs."&lt;br&gt;&lt;br&gt;
&lt;strong&gt;1940&lt;/strong&gt;: The term bug is used to describe a defect in direction-finding equipment in the film Flight Command.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;1942&lt;/strong&gt;: In a book, Louise Dickinson Rich refers to an ice cutting machine needing the "bugs" removed before it could resume operation.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;1944&lt;/strong&gt;: Isaac Asimov refers to bugs as issues with a robot in his short story "Catch That Rabbit."&lt;br&gt;&lt;br&gt;
The lexicon of computer science grew increasingly formal, arguably from the 1950s and certainly from the 1961's, as the Association for Computing Machinery (ACM) and other professional groups started publishing standardized glossaries. By the early 1960s, terms like "&lt;strong&gt;bug&lt;/strong&gt;" and "&lt;strong&gt;debug&lt;/strong&gt;" were used in mainstream language. As computing technology advanced, it also became widely used in the popular press and in everyday language. For instance, "Grin and Bear It" contained jokes about "computer bugs". Advertisements for services of various kinds assured the consumer with such slogans as "We'll Get the Bugs Out."&lt;/p&gt;

&lt;h2&gt;
  
  
  The cost of bugs
&lt;/h2&gt;

&lt;p&gt;It seems that computer bugs are like small, innocent pranks that prevent the engineering system from working at full capacity. But are they really that harmless?&lt;/p&gt;

&lt;p&gt;In 2002, software bugs cost the United States economy approximately $59.5 billion, which is a small figure considering the overall GDP of the USA. However, with the growth of digital services, the cost of bugs for the economy has grown proportionally. According to research by Tricentis, in 2016, software failures in the US cost the economy $1.1 trillion in assets. In total, software failures at 363 companies affected 4.4 billion customers and caused more than three and a half years of lost time. Since 2016, the damage to GDP has grown by almost one and a half times, and it is now estimated at 7% of the US GDP.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3qinvol2ll0zh86dahju.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3qinvol2ll0zh86dahju.png" alt="Cost of software bugs on the USA economic" width="800" height="494"&gt;&lt;/a&gt;&lt;br&gt;
Picture 2 - Cost of software bugs on the USA economic&lt;/p&gt;

&lt;p&gt;We've all heard about the famous Y2K bug, but do you know how much it cost the economy? To address the potential fallout, organizations globally invested heavily in Y2K remediation efforts. The total cost of these preventive measures is estimated to have ranged between $300 billion and $600 billion. This expenditure was incurred by governments, businesses, and other entities to update software, replace hardware, and implement extensive testing and contingency plans. Significant financial resources were allocated to ensure critical systems would transition smoothly into the new millennium. Governments, especially in developed countries, undertook extensive campaigns to prepare public services and infrastructure. Businesses, particularly those in finance, utilities, and transportation, conducted exhaustive checks and upgrades to mitigate the risks.&lt;/p&gt;

&lt;p&gt;But even with such investments to fix this bug, minor problems were still recorded:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The US official timekeeper, the Naval Observatory, reported the date as 19100 on its website.&lt;/li&gt;
&lt;li&gt;In Japan, the system collecting flight information for small planes failed.&lt;/li&gt;
&lt;li&gt;In Australia, bus ticket validation machines failed.&lt;/li&gt;
&lt;li&gt;In the US, over 150 slot machines at race tracks in Delaware failed.&lt;/li&gt;
&lt;li&gt;In Spain, a worker was summoned to an industrial tribunal on February 3, 1900.&lt;/li&gt;
&lt;li&gt;In South Korea, a district court summoned 170 people to court on January 4, 1900.&lt;/li&gt;
&lt;li&gt;In Italy, Telecom Italia sent out bills for the first two months of 1900.&lt;/li&gt;
&lt;li&gt;In the UK, some credit card transactions failed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bugs are expensive, but they also lead to not just financial losses, but far more serious consequences.&lt;/p&gt;

&lt;h3&gt;
  
  
  Intellectual Damage, which hampers the development of humanity
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1962&lt;/strong&gt;: NASA’s Mariner 1 Incident: In one of the earliest and most expensive software errors, NASA's Mariner 1 spacecraft, aimed at Venus, veered off course due to a missing hyphen in the code. This led to the spacecraft being destroyed shortly after launch, costing NASA $18 million. This incident underscored the critical need for meticulous coding and testing in software development.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;1996&lt;/strong&gt;: Ariane 5 Rocket Failure: A software error in the Ariane 5 rocket caused it to deviate from its path and self-destruct 37 seconds after launch. The problem stemmed from code reused from the Ariane 4, which was not compatible with the new rocket's flight conditions. The failure resulted in a loss of over $370 million, underscoring the critical need for software adaptation and testing in space missions.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;1999&lt;/strong&gt;: Mars Climate Orbiter Loss: NASA's Mars Climate Orbiter disintegrated upon arrival at Mars due to a software error involving unit conversion from English to metric measurements. The $327 million mission failure highlighted the importance of consistency and precision in software used for interplanetary exploration.&lt;/p&gt;

&lt;h3&gt;
  
  
  Political Damage (which almost triggered a war between nuclear powers):
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1980&lt;/strong&gt;: NORAD False Missile Alert: A software error caused NORAD to report a false missile attack on the United States. The mistake was due to a faulty circuit that the software did not account for, nearly triggering a nuclear response. This event highlighted the severe implications of software errors in military and defense systems.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;1983&lt;/strong&gt;: Soviet False Missile Alert: A Soviet satellite falsely reported incoming US missiles, almost leading to a nuclear counterstrike. The officer on duty trusted his instincts and chose not to react, preventing a potential disaster. This incident again emphasized the dire consequences of software errors in critical systems.&lt;/p&gt;

&lt;h3&gt;
  
  
  Environmental Damage (which also showed that bugs could be used as weapons):
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1982&lt;/strong&gt;: Siberian Gas Pipeline Explosion: In a Cold War incident, the CIA allegedly inserted faulty software into a Soviet gas pipeline control system, leading to an explosion visible from space. While the precise cost remains undisclosed, this event is remembered as one of the most monumental non-nuclear explosions, illustrating the destructive potential of intentional software bugs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bugs can also claim lives:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1985-1987&lt;/strong&gt;: Therac-25 Radiation Overdoses: A software bug in the Therac-25 radiation therapy machine resulted in patients receiving massive overdoses of radiation, causing several deaths and serious injuries. This tragic case demonstrated the fatal risks associated with software failures in medical devices and the essential need for rigorous testing and validation in healthcare technology.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;1994&lt;/strong&gt;: RAF Chinook Helicopter Crash: A software fault in the flight control system caused a Chinook helicopter to crash in Scotland, killing all 29 passengers. Initially blamed on pilot error, later investigations revealed the software glitch as the true cause, stressing the importance of reliable software in aviation safety.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;2000&lt;/strong&gt;: Panama City Radiation Overdoses: Faulty therapy planning software from Multidata caused radiation overdoses in patients, resulting in several deaths. This incident reiterated the deadly risks of software errors in medical applications and the crucial need for stringent testing protocols.&lt;/p&gt;

</description>
      <category>bug</category>
      <category>testing</category>
      <category>qa</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
