{"id":95,"date":"2026-02-26T00:35:54","date_gmt":"2026-02-26T00:35:54","guid":{"rendered":"https:\/\/sites.nd.edu\/softwaretesting\/?page_id=95"},"modified":"2026-02-26T14:00:01","modified_gmt":"2026-02-26T14:00:01","slug":"unit-testing","status":"publish","type":"page","link":"https:\/\/sites.nd.edu\/softwaretesting\/testing-types\/unit-testing\/","title":{"rendered":"Unit Testing"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"256\" height=\"256\" src=\"https:\/\/sites.nd.edu\/softwaretesting\/files\/2026\/02\/Unit-Testing.jpg\" alt=\"\" class=\"wp-image-96\" style=\"width:189px;height:auto\" srcset=\"https:\/\/sites.nd.edu\/softwaretesting\/files\/2026\/02\/Unit-Testing.jpg 256w, https:\/\/sites.nd.edu\/softwaretesting\/files\/2026\/02\/Unit-Testing-150x150.jpg 150w\" sizes=\"auto, (max-width: 256px) 100vw, 256px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><em><strong>What Is Unit Testing?<\/strong><\/em><\/h2>\n\n\n\n<p><strong>Unit testing<\/strong> is the practice of testing the smallest testable parts of a software system, such as individual functions, methods, or classes, to verify that each works correctly in isolation.<\/p>\n\n\n\n<p>A <em>unit<\/em> is typically a single piece of logic with a clear input and output. Unit tests confirm that this logic behaves as expected under normal conditions, edge cases, and error scenarios.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><\/ul>\n\n\n\n<table id=\"tablepress-6\" class=\"tablepress tablepress-id-6\">\n<thead>\n<tr class=\"row-1\">\n\t<th class=\"column-1\">Why It Matters<\/th><th class=\"column-2\">Who Performs It<\/th><th class=\"column-3\">When It Occurs<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-2\">\n\t<td class=\"column-1\"><ul><li>Detects defects <strong>early<\/strong>, when they are cheapest to fix<\/li><li>Improves code quality and design<\/li><li>Makes refactoring safer<\/li><li>Provides fast feedback during development<\/li><li>Reduces defects that reach later testing stages<\/li><\/ul><\/td><td class=\"column-2\"><ul><li>Software Developers<\/li><li>Sometimes supported by automated testing as part of CI\/CD pipelines<\/li><\/ul><\/td><td class=\"column-3\"><ul><li>During the <strong>development (coding) phase<\/strong><\/li><li>Before integration, system, or user acceptance testing<\/li><li>Re-run whenever code changes are made<\/li><\/ul><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-6 from cache -->\n\n\n\n<h2 class=\"wp-block-heading\"><em><strong>Typical Unit Testing Techniques<\/strong><\/em><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>White-Box Testing<\/strong>\n<ul class=\"wp-block-list\">\n<li>Tests are designed with full knowledge of the internal code structure.<\/li>\n\n\n\n<li><em>Purpose<\/em><strong><em>:<\/em><\/strong> Ensure all logical paths and conditions are exercised.<\/li>\n\n\n\n<li><em>Techniques include:<\/em>\n<ul class=\"wp-block-list\">\n<li>Statement coverage<\/li>\n\n\n\n<li>Branch coverage<\/li>\n\n\n\n<li>Path coverage<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Equivalence Partitioning<\/strong>\n<ul class=\"wp-block-list\">\n<li>Input data is divided into valid and invalid groups (partitions), and one value from each group is tested.<\/li>\n\n\n\n<li><em>Purpose<\/em>: Reduce the number of test cases while maintaining coverage.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Boundary Value Analysis<\/strong>\n<ul class=\"wp-block-list\">\n<li>Focuses on values at the edges of acceptable input ranges.<\/li>\n\n\n\n<li><em>Purpose<\/em>: Catch defects that often occur at limits (e.g., minimums and maximums).<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Error Handling &amp; Exception Testing<\/strong>\n<ul class=\"wp-block-list\">\n<li>Verifies how the unit behaves when invalid data, exceptions, or failures occur.<\/li>\n\n\n\n<li><em>Purpose<\/em>: Ensure graceful handling of errors and predictable system behavior.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Mocking and Stubbing<\/strong>\n<ul class=\"wp-block-list\">\n<li>External dependencies (databases, APIs, services) are replaced with simulated objects.<\/li>\n\n\n\n<li><em>Purpose<\/em>: Allow the unit to be tested in isolation, without relying on other components.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><em>Key Takeaways<\/em><\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Unit testing ensures individual pieces of code work correctly before they are combined into a complete system.<\/li>\n\n\n\n<li>Strong unit testing dramatically reduces downstream defects and creates a stable foundation for all other testing activities.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>What Is Unit Testing? Unit testing is the practice of testing the smallest testable parts of a software system, such as individual functions, methods, or classes, to verify that each works correctly in isolation. A unit is typically a single piece of logic with a clear input and output. Unit tests confirm that this logic [&hellip;]<\/p>\n","protected":false},"author":4975,"featured_media":0,"parent":43,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-95","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/sites.nd.edu\/softwaretesting\/wp-json\/wp\/v2\/pages\/95","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sites.nd.edu\/softwaretesting\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/sites.nd.edu\/softwaretesting\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/sites.nd.edu\/softwaretesting\/wp-json\/wp\/v2\/users\/4975"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.nd.edu\/softwaretesting\/wp-json\/wp\/v2\/comments?post=95"}],"version-history":[{"count":17,"href":"https:\/\/sites.nd.edu\/softwaretesting\/wp-json\/wp\/v2\/pages\/95\/revisions"}],"predecessor-version":[{"id":160,"href":"https:\/\/sites.nd.edu\/softwaretesting\/wp-json\/wp\/v2\/pages\/95\/revisions\/160"}],"up":[{"embeddable":true,"href":"https:\/\/sites.nd.edu\/softwaretesting\/wp-json\/wp\/v2\/pages\/43"}],"wp:attachment":[{"href":"https:\/\/sites.nd.edu\/softwaretesting\/wp-json\/wp\/v2\/media?parent=95"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}