<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[MI Raaz's Blog]]></title><description><![CDATA[I am a front-end focused full-stack developer.]]></description><link>https://raazmi.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 01 Sep 2026 16:27:21 GMT</lastBuildDate><atom:link href="https://raazmi.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Exploring Testing Code]]></title><description><![CDATA[What is testing?
Testing ensures that the code you've written works as intended. Imagine you're cooking. After completing each step, you taste your food and realize it's not good enough to eat. However, if you test as you cook, you can fix any mistak...]]></description><link>https://raazmi.hashnode.dev/exploring-testing-code</link><guid isPermaLink="true">https://raazmi.hashnode.dev/exploring-testing-code</guid><category><![CDATA[Testing]]></category><category><![CDATA[test]]></category><category><![CDATA[test driven development]]></category><dc:creator><![CDATA[Md Mirajul Islam]]></dc:creator><pubDate>Mon, 26 Feb 2024 19:39:26 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/95YRwf6CNw8/upload/b45ea3318212f5b063e11d6eed6ac6dc.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-what-is-testing">What is testing?</h3>
<p>Testing ensures that the code you've written works as intended. Imagine you're cooking. After completing each step, you taste your food and realize it's not good enough to eat. However, if you test as you cook, you can fix any mistakes before it's too late. Testing in code is just like that. It's a way to check software or applications before they're fully made, so you can spot and fix any problems early on.</p>
<h3 id="heading-why-we-need-testing">Why we need testing?</h3>
<p>Testing is super important in software engineering. Imagine you're building an app. After writing lots of code, you add a new feature that changes some old code. But when you try it out, the app breaks! Now, you have to test the whole app to make sure everything else still works. This is called manual testing, and it takes a lot of time. But if you write automated test cases for each part of your app, you don't need to test manually every time. With a single command, you can test the whole app! Automated testing takes extra time upfront, but it saves a lot of times compared to manual testing. Plus, it gives us consistency and reliability, making us more confident there are fewer errors in our app.</p>
<h3 id="heading-types-of-testing">Types of testing</h3>
<p>There are three types of testing.</p>
<ol>
<li><p><strong>Unit Testing:</strong> This involves testing individual units or components of the software independently. It focuses on verifying that each unit functions correctly as expected..</p>
</li>
<li><p><strong>Integration Testing</strong>: Integration testing checks if different units or modules of the software work together seamlessly when integrated. It ensures that interactions between various components do not cause unexpected behavior.</p>
</li>
<li><p><strong>End-to-end Testing:</strong> End-to-end testing assesses the complete functionality and workflow of an application, from start to finish, ensuring seamless performance across all components and integrations in a real-world environment like a real person.</p>
</li>
</ol>
<h3 id="heading-test-example">Test Example</h3>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">multiply</span>(<span class="hljs-params">a, b</span>) </span>{
    <span class="hljs-keyword">return</span> a * b;
}

<span class="hljs-keyword">const</span> multiplyResult = multiply(<span class="hljs-number">5</span>, <span class="hljs-number">2</span>);

<span class="hljs-comment">// Write our test, we know 5 * 2 = 10</span>
<span class="hljs-keyword">if</span> (multiplyResult !== <span class="hljs-number">10</span>) {
    <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">"Multiply with the argument 5 and 2 should return 10"</span>);
}
</code></pre>
<p>In this example, we're testing a function called <strong>multiply</strong>. We want this function to always give us 10 when we give it 5 and 2 as arguments. We're writing this test manually. But, there are many testing libraries for JavaScript like Jest, Mocha, Enzyme, Jasmine, etc., that make testing easier. The other languages definitely have library for testing.</p>
<p>If we use Jest to write the same test for our <strong>multiply</strong> function, here's how it would look:</p>
<pre><code class="lang-javascript">test(<span class="hljs-string">"multiply 5 * 2 should be 10"</span>, <span class="hljs-function">() =&gt;</span> {
    expect(multiply(<span class="hljs-number">5</span>, <span class="hljs-number">2</span>)).toBe(<span class="hljs-number">10</span>);
});
</code></pre>
<h3 id="heading-test-driven-development-tdd">Test Driven Development (TDD)</h3>
<p>Test-driven development is a way of writing code where you first write tests to check what your code should do. Then, you write the actual code to make those tests pass. This helps make sure your code does what it's supposed to and stays working even if you change it later. It also helps you think about potential problems early on and makes your code easier to understand and update.</p>
]]></content:encoded></item></channel></rss>