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

<channel>
	<title>Automation Testing - TheCodeBuzz</title>
	<atom:link href="https://thecodebuzz.com/category/automation-testing/feed/" rel="self" type="application/rss+xml" />
	<link>https://thecodebuzz.com</link>
	<description>Best Practices for Software Development</description>
	<lastBuildDate>Sun, 10 Mar 2024 20:41:24 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://thecodebuzz.com/wp-content/uploads/2022/11/cropped-android-chrome-512x512-1-1-51x51.jpg</url>
	<title>Automation Testing - TheCodeBuzz</title>
	<link>https://thecodebuzz.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Top 10 Benefits of Unit Testing &#8211; Awesome Code</title>
		<link>https://thecodebuzz.com/top-10-benefits-of-unit-testing-awesome-code/</link>
					<comments>https://thecodebuzz.com/top-10-benefits-of-unit-testing-awesome-code/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 02 Jul 2023 04:08:02 +0000</pubDate>
				<category><![CDATA[Automation Testing]]></category>
		<category><![CDATA[Integration Testing]]></category>
		<category><![CDATA[Test Automation]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[10 Benefits of Unit Testing - Awesome Code]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=27779</guid>

					<description><![CDATA[<p>Top 10 Benefits of Unit Testing &#8211; Awesome Code Today, we&#8217;ll discuss the top 10 Benefits of Unit Testing procedures in this article. Unit testing is a powerful method that has become well-known. Software is broken down into its most basic functional units during unit testing, and these components are then put through a rigorous [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/top-10-benefits-of-unit-testing-awesome-code/">Top 10 Benefits of Unit Testing – Awesome Code</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading">Top 10 Benefits of Unit Testing &#8211; Awesome Code</h1>



<p>Today, we&#8217;ll discuss the top 10 Benefits of Unit Testing procedures in this article. </p>



<p></p>



<p>Unit testing is a powerful method that has become well-known.</p>



<p></p>



<p>Software is broken down into its most basic functional units during unit testing, and these components are then put through a rigorous testing process. </p>



<p></p>



<p>The many advantages of unit testing will be discussed in this article, along with how it enhances the quality of software development as a whole.</p>



<p></p>



<p>We will see below benefits,</p>



<p></p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-improved-code-quality-benefits-of-unit-testing">Improved Code Quality  &#8211; Benefits of Unit Testing</a></li><li><a href="#aioseo-early-defect-bug-detection">Early Defect/Bug Detection</a></li><li><a href="#aioseo-facilitates-refactoring-and-code-maintenance">Facilitates Refactoring and Code Maintenance</a></li><li><a href="#aioseo-promotes-teamwork-and-collaboration">Promotes Teamwork and Collaboration</a></li><li><a href="#aioseo-unit-test-as-code-documentation">Unit Test as Code Documentation</a></li><li><a href="#aioseo-create-mock-behavior-describe-and-test-unexpected-behavior">Create Mock behavior &#8211; Describe and test Unexpected behavior</a></li><li><a href="#aioseo-controlled-test-scenarios-execution">Controlled Test Scenarios execution</a></li><li><a href="#aioseo-faster-debugging-and-troubleshooting">Faster Debugging and Troubleshooting</a></li><li><a href="#aioseo-test-driven-development-tdd">Test-Driven Development (TDD)</a></li><li><a href="#aioseo-summary">Summary</a></li></ul></div>



<p></p>



<h2 class="wp-block-heading" id="aioseo-improved-code-quality-benefits-of-unit-testing">Improved Code Quality  &#8211; Benefits of Unit Testing</h2>



<p></p>



<p>Unit testing helps developers identify and eliminate bugs at an early stage of development.</p>



<p>By writing tests that target individual units of code, such as functions or methods, developers can ensure that each unit behaves correctly in isolation. </p>



<p>This systematic approach to testing promotes clean and modular code design, leading to improved code quality. </p>



<p>With each unit passing its tests, developers gain confidence in the correctness of their codebase, reducing the likelihood of introducing bugs during subsequent development phases.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-early-defect-bug-detection">Early Defect/Bug Detection </h2>



<p></p>



<p><a href="https://www.thecodebuzz.com/tdd-unit-testing-naming-conventions-and-standards/" target="_blank" rel="noopener" title="Unit Test Naming Conventions Best Practices">Unit testing </a>facilitates the detection of bugs at an early stage, allowing developers to address them promptly. </p>



<p></p>



<p>By isolating and testing individual units of code, issues can be identified before they propagate into complex and interconnected parts of the system. </p>



<p></p>



<p>This early bug detection significantly reduces the debugging effort required in later stages of development and enhances the overall efficiency of the software development process.</p>



<p></p>



<p></p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-facilitates-refactoring-and-code-maintenance">Facilitates Refactoring and Code Maintenance </h2>



<p></p>



<p> Unit testing plays a vital role in code refactoring and maintenance. </p>



<p></p>



<p>Refactoring involves restructuring code without changing its external behavior. </p>



<p></p>



<p>Unit tests provide a safety net during refactoring, ensuring that the desired functionality is maintained after modifications. </p>



<p></p>



<p>By running unit tests after each refactoring step, developers can quickly identify any unintended side effects or regression issues. </p>



<p></p>



<p>This encourages developers to refactor code fearlessly, leading to cleaner, more maintainable codebases and making it easier to accommodate changing requirements or enhancements.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-promotes-teamwork-and-collaboration">Promotes Teamwork and Collaboration</h2>



<p></p>



<p>Teamwork is encouraged in software development initiatives through <a href="https://www.thecodebuzz.com/unit-testing-best-practices/" target="_blank" rel="noopener" title="Unit Test Best Practices in Code Development">unit testing</a>. Individual unit testing makes it simpler for several developers to work on various system components at once.</p>



<p></p>



<p>Thanks to the current unit tests, each developer may be confident that their changes have not caused any regression problems.</p>



<p></p>



<p>Unit tests also act as living documentation, giving developers a clear grasp of the desired behavior of certain pieces of code and enhancing teamwork.</p>



<p></p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-unit-test-as-code-documentation">Unit Test as Code Documentation </h2>



<p></p>



<p>Unit tests act as living documentation, illustrating how individual units of code should behave. By reading unit tests, developers gain insights into the expected inputs, outputs, and interactions of code components. </p>



<p></p>



<p>This documentation aspect is invaluable when new developers join a project or when revisiting code after a significant period. </p>



<p></p>



<p>Unit tests serve as executable examples, helping developers understand the codebase faster and encouraging adherence to coding standards and best practices.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-create-mock-behavior-describe-and-test-unexpected-behavior">Create Mock behavior &#8211; Describe and test Unexpected behavior </h2>



<p></p>



<p><a href="https://www.thecodebuzz.com/unit-testing-controller-sync-and-async-methods-asp-net-core-example/" target="_blank" rel="noopener" title="Unit Test and Mock Sync/Async Controller Methods in ASP.NET Core">Mocking </a>simplifies the setup process for unit tests by eliminating the need to configure or provision real external systems. </p>



<p></p>



<p>With mock objects or functions, developers can define the expected interactions and outputs without worrying about complex setup procedures. </p>



<p></p>



<p>This simplification accelerates the test preparation phase, reducing the overhead associated with configuring and maintaining test environments. It also makes it easier to replicate.</p>



<p></p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-controlled-test-scenarios-execution">Controlled Test Scenarios execution</h2>



<p></p>



<p>Unit testing lets you go above and beyond considering testing. </p>



<p>You can go to any extent by unit testing your module and making them great. </p>



<p>For example, Mocking empowers developers to have precise control over various test scenarios. </p>



<p>By creating test objects or functions, developers can define specific behaviors, responses, or inputs for the simulated dependencies. </p>



<p> Developers can systematically cover a wide range of test cases, ensuring comprehensive test coverage and enhancing the overall reliability of the software.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-faster-debugging-and-troubleshooting">Faster Debugging and Troubleshooting</h2>



<p></p>



<p>The particular location of the problem is shown when a unit test fails, making it easier for developers to identify the root cause.</p>



<p></p>



<p>Unit tests act as a safety net while debugging and troubleshooting software.</p>



<p></p>



<p>With less time spent searching through large code bases for issues, developers may more quickly and efficiently correct errors thanks to this targeted approach to debugging.</p>



<p></p>



<p>By reducing the amount of time spent on debugging, unit testing helps developers maintain the development momentum and deliver high-quality software on time.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-test-driven-development-tdd">Test-Driven Development (TDD)</h2>



<p></p>



<p>Unit testing is a core practice in TDD. Developers write tests before implementing the code, using them as a guide to drive the development process and ensure test coverage. </p>



<p>Unit tests act as a form of regression testing, ensuring that previously implemented functionality continues to work as expected after changes or updates.</p>



<p></p>



<p>While unit testing focuses on testing individual units, it also aids integration testing. By isolating units, developers can verify that they interact correctly when combined, detecting issues early in the integration process.</p>



<p></p>



<p></p>



<p style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size"></p>



<p style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size"></p>



<p class="has-medium-font-size"><strong>Happy Coding </strong>!!</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-summary">Summary</h2>



<p></p>



<p>Unit testing is an essential method in software development that provides several advantages that enhance the quality of software systems. Unit testing benefits the entire development process by enhancing the quality of the code, enabling early issue identification, accelerating debugging, assisting code refactoring, encouraging collaboration, and offering code documentation. It enables programmers to create durable, maintainable code.</p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p>



<p></p>



<p></p><p>The post <a href="https://thecodebuzz.com/top-10-benefits-of-unit-testing-awesome-code/">Top 10 Benefits of Unit Testing – Awesome Code</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/top-10-benefits-of-unit-testing-awesome-code/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Unit Tests An Asynchronous Method In .NET Core Example</title>
		<link>https://thecodebuzz.com/moq-to-mock-asynchronous-method-net-core-unit-tests/</link>
					<comments>https://thecodebuzz.com/moq-to-mock-asynchronous-method-net-core-unit-tests/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 01 Mar 2022 00:00:00 +0000</pubDate>
				<category><![CDATA[.NET Core]]></category>
		<category><![CDATA[Automation Testing]]></category>
		<category><![CDATA[mock an Asynchronous Method in .NET Core]]></category>
		<category><![CDATA[Unit test an Asynchronous Method in .NET Core Unit Tests]]></category>
		<category><![CDATA[unit testing async method .net core]]></category>
		<category><![CDATA[using moq for async method]]></category>
		<guid isPermaLink="false">https://thecodebuzz.com/?p=6194</guid>

					<description><![CDATA[<p>Using Moq to mock an Asynchronous Method in .NET Core Unit Tests Today in this article, we will learn how to Unit Tests An Asynchronous Method In .NET Core with examples. Below are a few examples of the .NET core-based common unit testing sample and their resolution using mocking. Today in this article, we will [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/moq-to-mock-asynchronous-method-net-core-unit-tests/">Unit Tests An Asynchronous Method In .NET Core Example</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading"><strong>Using Moq to mock an Asynchronous Method in .NET Core Unit Tests</strong></h1>



<figure class="wp-block-image"><img fetchpriority="high" decoding="async" width="1351" height="520" src="https://i0.wp.com/thecodebuzz.com/wp-content/uploads/2019/11/moq-to-mock-asynchronous-method-net-core-unit-tests.jpg?fit=785%2C302&amp;ssl=1" alt="Unit Tests An Asynchronous Method In .NET Core Example" class="wp-image-6324" srcset="https://thecodebuzz.com/wp-content/uploads/2019/11/moq-to-mock-asynchronous-method-net-core-unit-tests.jpg 1351w, https://thecodebuzz.com/wp-content/uploads/2019/11/moq-to-mock-asynchronous-method-net-core-unit-tests-300x115.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2019/11/moq-to-mock-asynchronous-method-net-core-unit-tests-1024x394.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2019/11/moq-to-mock-asynchronous-method-net-core-unit-tests-768x296.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2019/11/moq-to-mock-asynchronous-method-net-core-unit-tests-785x302.jpg 785w" sizes="(max-width: 1351px) 100vw, 1351px" /></figure>



<p>Today in this article, we will learn how to Unit Tests An Asynchronous Method In .NET Core with examples. Below are a few examples of the .NET core-based common unit testing sample and their resolution using mocking.</p>



<p></p>



<p>Today in this article, we will cover below aspects,</p>



<p></p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-resolution">Resolution</a></li><li><a href="#aioseo-better-assertion">Better Assertion</a></li></ul></div>



<p></p>



<p>Here I am testing a controller Method that makes an asynchronous call to an external service using HTTPClient.</p>



<p> </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; title: ; notranslate">
        &#x5B;HttpGet]
        public async Task&lt;IActionResult&gt; GetAsync(string id)
        {
            Book book = null;
            try
            {
                // Test await method - Asynchronously 
                book = await _bookService.GetAsync(id);
                book.Price = 10;
                if (book == null)
                {
                    return NotFound();
                }
            }
            catch(Exception ex)
            {
            }
            // do more stuff

            return Ok(book);
        }

</pre></div>


<p></p>



<h2 class="wp-block-heading" id="aioseo-resolution">Resolution</h2>



<p></p>



<p>Below is an example of how we can write unit test cases,</p>



<p>We will follow the AAA pattern where we will perform Arrange, Act, and Assertion.</p>



<p>Below is an example of mocking the Async method of Interface.</p>



<pre class="wp-block-preformatted has-medium-font-size">   var mockBookClient= new Mock&lt;IBookService&gt;();
   mockBookClient.Setup(c =&gt; c.GetAsync(document .Id)).ReturnsAsync(document);</pre>



<p></p>



<p>Below is a complete sample example,</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; title: ; notranslate">
       
        &#x5B;Fact]
        public async Task BookService_GetBookAsync_With_ValidBookID()
        {
            //Arrange
            Book document = new Book()
            {
                Author = &quot;The&quot;,
                BookName = &quot;CodeBUzz&quot;,
                Id = &quot;1234&quot;
            };

            var mockBookClient= new Mock&lt;IBookService&gt;();
            mockBookClient.Setup(c =&gt; c.GetAsync(document .Id)).ReturnsAsync(document);

            //Act
            BooksController service = new BooksController(mockBookClient.Object);
            var result = await service.GetAsync(bookID);

            //Assert
            Assert.NotNull(result);

        }
</pre></div>


<p></p>



<h2 class="wp-block-heading" id="aioseo-better-assertion">Better Assertion </h2>



<p></p>



<p>If you would like to do a more rigorous assert on the return object which is always recommended, please use the below code to perform better assertion. </p>



<p></p>



<figure class="wp-block-image"><img decoding="async" width="1152" height="924" src="https://i0.wp.com/thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-async-method-and-moq-mocking.jpg?fit=785%2C629&amp;ssl=1" alt="Unit Tests An Asynchronous Method In .NET Core Example" class="wp-image-6451" srcset="https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-async-method-and-moq-mocking.jpg 1152w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-async-method-and-moq-mocking-300x241.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-async-method-and-moq-mocking-1024x821.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-async-method-and-moq-mocking-768x616.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2019/11/unit-testing-async-method-and-moq-mocking-648x520.jpg 648w" sizes="(max-width: 1152px) 100vw, 1152px" /></figure>



<p></p>



<p>The below article mentions the checklist one should be aware of while Unit Testing an API Interface(Controller).</p>



<p></p>



<p><strong><em>References :</em></strong></p>



<p></p>



<ul class="has-medium-font-size wp-block-list">
<li><em><a href="https://www.thecodebuzz.com/restful-api-controller-unit-testing-best-practices/" target="_blank" rel="noreferrer noopener">RESTFul API/Controller Unit Testing – Best Practices</a></em></li>
</ul>



<ul class="has-medium-font-size wp-block-list">
<li><em><a href="https://www.thecodebuzz.com/tdd-unit-testing-naming-conventions-and-standards/" target="_blank" rel="noreferrer noopener"></a><em><a href="https://www.thecodebuzz.com/tdd-unit-testing-naming-conventions-and-standards/" target="_blank" rel="noreferrer noopener">Unit Test cases Naming Conventions &#8211; Best Practices</a></em></em></li>
</ul>



<p></p>



<p>Please note that we need to use <strong>ReturnsAsync</strong> instead of Returns to avail and set up the mock result using <strong>Moq</strong> for asynchronous operation.</p>



<p></p>



<p></p>



<p style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size"></p>



<p style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size"></p>



<p class="has-medium-font-size"><strong>Happy Coding </strong>!!</p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p><strong> </strong></p>



<p></p><p>The post <a href="https://thecodebuzz.com/moq-to-mock-asynchronous-method-net-core-unit-tests/">Unit Tests An Asynchronous Method In .NET Core Example</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/moq-to-mock-asynchronous-method-net-core-unit-tests/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Order Test cases by Display Name</title>
		<link>https://thecodebuzz.com/xunit-test-case-order-by-display-name/</link>
					<comments>https://thecodebuzz.com/xunit-test-case-order-by-display-name/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 10 Nov 2021 03:00:00 +0000</pubDate>
				<category><![CDATA[Automation]]></category>
		<category><![CDATA[Automation Testing]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=17551</guid>

					<description><![CDATA[<p>Test case Order (Unit Test or Functional Test) by Display Name Today in this article we shall cover how to execute and Order Test cases by Display Name As we already learned other techniques for ordering the test cases. Ordering on test cases can be achieved by any of the below mechanisms, Please see for [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/xunit-test-case-order-by-display-name/">How to Order Test cases by Display Name</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading"><strong>Test case Order (Unit Test or Functional Test) by Display Name</strong></h1>



<figure class="wp-block-image size-large"><a href="https://www.thecodebuzz.com/order-unit-test-cases-or-integration-testing-guidelines/" target="_blank" rel="noopener"><img decoding="async" width="1024" height="391" src="https://www.thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-by-collection-name-1024x391.jpg" alt="XUnit Test case Order by Display Name" class="wp-image-17557" srcset="https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-by-collection-name-1024x391.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-by-collection-name-300x115.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-by-collection-name-768x293.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-by-collection-name-1536x587.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-by-collection-name-2048x783.jpg 2048w, https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-by-collection-name-785x300.jpg 785w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></figure>



<p>Today in this article we shall cover how to execute and Order Test cases by Display Name</p>



<p></p>



<p>As we already learned other techniques for ordering the test cases.</p>



<p></p>



<p>Ordering on test cases can be achieved by any of the below mechanisms,</p>



<p></p>



<ul class="wp-block-list">
<li><strong>Alphabetical </strong>&#8211; Order test method based on test name&#8217;s Alphabetical order</li>
</ul>



<p></p>



<p>Please see for more details: <a href="https://www.thecodebuzz.com/order-unit-test-cases-or-integration-testing-guidelines/" target="_blank" rel="noopener" title="How to Order Unit Test cases – Guidelines"><em><strong>How to Order Unit Test cases by Alphabetical – Guidelines</strong></em></a></p>



<p></p>



<ul class="wp-block-list">
<li><strong>Priority</strong>&#8211; Order test method based on test name&#8217;s using priority order set by the user providing better control on execution.</li>
</ul>



<p></p>



<p>Please see for more details: <a href="https://www.thecodebuzz.com/order-unit-test-cases-or-integration-testing-guidelines/" target="_blank" rel="noreferrer noopener"><em><strong>How to Order Unit Test cases by </strong></em></a><em><strong><a href="https://www.thecodebuzz.com/order-unit-test-cases-or-integration-testing-guidelines/" target="_blank" rel="noreferrer noopener">Priority</a></strong></em><a href="https://www.thecodebuzz.com/order-unit-test-cases-or-integration-testing-guidelines/" target="_blank" rel="noreferrer noopener"><em><strong> – Guidelines</strong></em></a></p>



<p></p>



<p><strong>DisplayName </strong>&#8211; Order test method based on test name&#8217;s DisplayName order we shall cover this in today&#8217;s article,</p>



<p></p>



<p>Implement the <code><strong>ITestCaseOrderer</strong></code> and provide an ordering mechanism. </p>



<p></p>



<p>With this, we will order the Test cases using the <strong><em>collection name</em></strong>.</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [8]; title: ; notranslate">
using System.Collections.Generic;
using System.Linq;
using Xunit;
using Xunit.Abstractions;

namespace OrechstrationService.Project
{
    public class DisplayNameOrderer : ITestCollectionOrderer
        {
            public IEnumerable&lt;ITestCollection&gt; OrderTestCollections(
                IEnumerable&lt;ITestCollection&gt; testCollections) =&gt;
                testCollections.OrderBy(collection =&gt; collection.DisplayName);
        }

}

</pre></div>


<p></p>



<p><strong><em>TestCaseOrderer </em></strong>now can be defined using <em><strong>DisplayNameOrderer </strong></em>as below. Please note to add below two attributes on the test cases namespace used for the test project,</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; title: ; notranslate">
&#x5B;assembly: CollectionBehavior(DisableTestParallelization = true)]
&#x5B;assembly: TestCollectionOrderer(&quot;OrechstrationService.Project.DisplayNameOrderer&quot;, &quot;OrechstrationService.Project&quot;)]
</pre></div>


<p></p>



<p>One can define the collection name using the Collection attribute as below. </p>



<p></p>



<p>Here you can decorate the test class with the collection names, Ex. Saving Account TestCollection</p>



<p></p>



<p><strong>Example</strong></p>



<p></p>



<pre class="wp-block-preformatted">[Collection("Saving Account TestCollection")]

<code>[Collection("Credit Account TestCollection")]</code>

[Collection("Bank AccountTest Collection")]
</pre>



<p></p>



<p>Here below is a complete example,</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [10,31,53]; title: ; notranslate">
using Xunit;


// Need to turn off test parallelization so we can validate the run order
&#x5B;assembly: CollectionBehavior(DisableTestParallelization = true)]
&#x5B;assembly: TestCollectionOrderer(&quot;OrechstrationService.Project.DisplayNameOrderer&quot;, &quot;OrechstrationService.Project&quot;)]
namespace OrechstrationService.Project.Http
{

    &#x5B;Collection(&quot;Saving Account TestCollection&quot;)]
    public class HttpHelperClassTests1
    {
        public static bool SavingAccountTestCollection;

        &#x5B;Fact]
        public static void SavinggAccountController_OnGetAccount_Valid_HTTPClient()
        {
            //Arrange

            //Act

            //Assert
            Assert.True(HttpHelperClassTests2.CreditAccountTestCollection);
            Assert.True(HttpHelperClassTests3.BankAccountTestCollection);
            SavingAccountTestCollection = true;


        }
    }

    &#x5B;Collection(&quot;Credit Account TestCollection&quot;)]
    public class HttpHelperClassTests2
    {
        public static bool CreditAccountTestCollection;


        &#x5B;Fact]
        public static void CreditController_OnGetAccount_Valid_Typed_HTTPClient()
        {

            //Arrange

            //Act

            //Assert
            Assert.False(HttpHelperClassTests1.SavingAccountTestCollection);    
            Assert.True(HttpHelperClassTests3.BankAccountTestCollection);
            CreditAccountTestCollection = true;
        }

    }

    &#x5B;Collection(&quot;Bank AccountTest Collection&quot;)]
    public class HttpHelperClassTests3
    {
        public static bool BankAccountTestCollection;

        &#x5B;Fact]
        public static void BankController_OnGetAccount_Valid_Typed_HTTPClient()
        {

            //Arrange

            //Act

            //Assert

            Assert.False(HttpHelperClassTests1.SavingAccountTestCollection);
            Assert.False(HttpHelperClassTests2.CreditAccountTestCollection);
            BankAccountTestCollection = true;

        }

    }
}

</pre></div>


<p></p>



<p>Once executed test cases execution order will be as per the collection name order alphabetically,</p>



<p></p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://www.thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-by-display-name-collection-1024x328.jpg" alt="Order Test cases by Display Name" class="wp-image-17554" width="725" height="232" srcset="https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-by-display-name-collection-1024x328.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-by-display-name-collection-300x96.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-by-display-name-collection-768x246.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-by-display-name-collection-1536x491.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-by-display-name-collection-785x251.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-by-display-name-collection.jpg 1607w" sizes="auto, (max-width: 725px) 100vw, 725px" /></figure>



<p></p>



<p><strong><em>References </em></strong>:</p>



<p></p>



<ul class="wp-block-list">
<li><a href="https://www.thecodebuzz.com/order-unit-test-cases-or-integration-testing-guidelines/" target="_blank" rel="noreferrer noopener" title="How to Order Unit Test cases – Guidelines"><em><strong>How to Order XUnit Test cases by Alphabetical – Guidelines</strong></em></a></li>
</ul>



<p></p>



<ul class="wp-block-list">
<li><a href="https://www.thecodebuzz.com/order-unit-test-cases-or-integration-testing-guidelines/" target="_blank" rel="noreferrer noopener"><em><strong>How to Order XUnit Test cases by </strong></em></a><em><strong><a href="https://www.thecodebuzz.com/order-unit-test-cases-or-integration-testing-guidelines/" target="_blank" rel="noreferrer noopener">Priority</a></strong></em><a href="https://www.thecodebuzz.com/order-unit-test-cases-or-integration-testing-guidelines/" target="_blank" rel="noreferrer noopener"><em><strong> – Guidelines</strong></em></a></li>
</ul>



<p></p>



<p></p>



<p style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size"></p>



<p style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size"></p>



<p class="has-medium-font-size"><strong>Happy Coding </strong>!!</p>



<p></p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p><p>The post <a href="https://thecodebuzz.com/xunit-test-case-order-by-display-name/">How to Order Test cases by Display Name</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/xunit-test-case-order-by-display-name/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Unit Test Best Practices in Code Development</title>
		<link>https://thecodebuzz.com/unit-testing-best-practices/</link>
					<comments>https://thecodebuzz.com/unit-testing-best-practices/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 01 Sep 2021 01:24:00 +0000</pubDate>
				<category><![CDATA[Automation Testing]]></category>
		<category><![CDATA[XP Practices]]></category>
		<category><![CDATA[unit test best practices c#]]></category>
		<category><![CDATA[unit test best practices google]]></category>
		<category><![CDATA[unit test best practices javascript]]></category>
		<category><![CDATA[unit test best practices microsoft]]></category>
		<category><![CDATA[unit test best practices python]]></category>
		<category><![CDATA[unit test best practices stack overflow]]></category>
		<category><![CDATA[unit test coverage best practice]]></category>
		<category><![CDATA[Unit Testing Best Practices -Test Driven Development]]></category>
		<category><![CDATA[which three items are best practices for unit tests]]></category>
		<guid isPermaLink="false">https://go-digital-development.com/?p=1252</guid>

					<description><![CDATA[<p>Unit Test Best Practices &#8211; Test-Driven Development Today in this article, we will understand What is Unit tests and Unit Test Best Practices in Software Development. We will cover the below aspects in the below article, Why Unit Tests? Your application/service consists of a bunch of functionalities built together to perform business operations. These small/large [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/unit-testing-best-practices/">Unit Test Best Practices in Code Development</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading">Unit Test Best Practices &#8211; Test-Driven Development</h1>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="450" src="https://www.thecodebuzz.com/wp-content/uploads/2021/08/Unit-Testing-Best-Practices-1024x450.jpg" alt="Unit Testing Best Practices -Test-Driven Development" class="wp-image-17946" srcset="https://thecodebuzz.com/wp-content/uploads/2021/08/Unit-Testing-Best-Practices-1024x450.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/08/Unit-Testing-Best-Practices-300x132.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/08/Unit-Testing-Best-Practices-768x337.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/08/Unit-Testing-Best-Practices-1536x675.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/08/Unit-Testing-Best-Practices-2048x900.jpg 2048w, https://thecodebuzz.com/wp-content/uploads/2021/08/Unit-Testing-Best-Practices-785x345.jpg 785w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Today in this article, we will understand What is Unit tests and Unit Test Best Practices in Software Development.</p>



<p>We will cover the below aspects in the below article,</p>



<p></p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-why-unit-tests">Why Unit Tests?</a></li><li><a href="#aioseo-where-to-start">Where to start?</a></li><li><a href="#aioseo-best-practices-for-unit-testing">Best Practices for Unit Testing</a></li><li><a href="#aioseo-best-practices-for-unit-testing">Best practices for Unit Testing</a></li><li><a href="#aioseo-some-additional-best-practices-and-guidelines-for-unit-test-cases">Some additional best practices and guidelines for Unit Test cases,</a></li></ul></div>



<p></p>



<h2 class="wp-block-heading" id="aioseo-why-unit-tests"><strong>Why Unit Tests?</strong></h2>



<p></p>



<p>Your application/service consists of a bunch of functionalities built together to perform business operations. These small/large bunch of functionality together makes your application complete in a sense. </p>



<p></p>



<p>It&#8217;s important these small individual functionalities are robust enough to make sure your application performs best in a real production environment.</p>



<p></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="538" src="https://www.thecodebuzz.com/wp-content/uploads/2021/08/UnitTest-Best-practices-1024x538.jpg" alt="unit test best practices" class="wp-image-17943" srcset="https://thecodebuzz.com/wp-content/uploads/2021/08/UnitTest-Best-practices-1024x538.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/08/UnitTest-Best-practices-300x158.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/08/UnitTest-Best-practices-768x404.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/08/UnitTest-Best-practices-1536x808.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/08/UnitTest-Best-practices-785x413.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2021/08/UnitTest-Best-practices.jpg 1856w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<p>How will you make sure these small pieces in your application will be robust??</p>



<p></p>



<p>There is no other better way than Unit Test. Unit Test is the FIRST thing you should do to make your application robust. Tests are termed <a href="https://www.thecodebuzz.com/top-10-benefits-of-unit-testing-awesome-code/">unit tests</a> because here the emphasis is on each individual piece of application. Each small individual<strong> method </strong>is important and represents a unit and hence needs to be tested in isolation.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-where-to-start">Where to start?</h2>



<p></p>



<p class="has-normal-font-size">We understand the concept of Unit Tests but there is always confusion on “Where to start”. Isn&#8217;t it? </p>



<p></p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://www.thecodebuzz.com/wp-content/uploads/2021/08/UnitTest-Best-practices-flow-1024x513.jpg" alt="Unit Testing checklist" class="wp-image-17944" width="562" height="281" srcset="https://thecodebuzz.com/wp-content/uploads/2021/08/UnitTest-Best-practices-flow-1024x513.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/08/UnitTest-Best-practices-flow-300x150.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/08/UnitTest-Best-practices-flow-768x385.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/08/UnitTest-Best-practices-flow-785x393.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2021/08/UnitTest-Best-practices-flow.jpg 1535w" sizes="auto, (max-width: 562px) 100vw, 562px" /></figure>



<p class="has-normal-font-size">I have simplified as below,</p>



<p></p>



<blockquote class="wp-block-quote is-style-large is-layout-flow wp-block-quote-is-layout-flow">
<p>All public functions within a class (created by you) require a unit test.</p>
</blockquote>



<p></p>



<p>So if you want to start somewhere in an existing application, then start with a small class and a simple method in the class. </p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="208" src="https://www.thecodebuzz.com/wp-content/uploads/2021/08/Unit-Testing-Best-Practice-1024x208.jpg" alt="What is Unit test ?" class="wp-image-17945" srcset="https://thecodebuzz.com/wp-content/uploads/2021/08/Unit-Testing-Best-Practice-1024x208.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/08/Unit-Testing-Best-Practice-300x61.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/08/Unit-Testing-Best-Practice-768x156.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/08/Unit-Testing-Best-Practice-1536x311.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/08/Unit-Testing-Best-Practice-785x159.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2021/08/Unit-Testing-Best-Practice.jpg 1657w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Now we got an answer for where to start. </p>



<p></p>



<p>Let&#8217;s look into a few best practices in general that we can follow. Please understand there are many best practices before we get crazed about this. but there are a few best-of-best practices that should be enough to write better unit test cases. </p>



<p>Here we really need not have to bother about <strong>Test First vs</strong> <strong>Code First. </strong>These best practices are generic enough to be applied to any approach of development you are using.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-best-practices-for-unit-testing">Best Practices for Unit Testing </h2>



<p></p>



<p>In an all-to-remember unit test cases should follow the <strong><em>FIRST</em></strong> principle,</p>



<p></p>



<p style="font-size:28px">F = Fast </p>



<p style="font-size:28px">I  = Isolated </p>



<p style="font-size:28px">R = Repeatable </p>



<p style="font-size:28px">S = Self-checking<strong> </strong></p>



<p style="font-size:28px">T = Timely </p>



<p></p>



<p>This <strong>FIRST </strong>approach is explained in detail as below,</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-best-practices-for-unit-testing">Best practices for Unit Testing</h2>



<p></p>



<p><strong> </strong></p>



<blockquote class="wp-block-quote is-style-large is-layout-flow wp-block-quote-is-layout-flow">
<p><strong>1. Unit test cases should be Fast</strong>. </p>
</blockquote>



<p></p>



<p> Yes &#8211; every test should <strong>run </strong>within <strong>milliseconds</strong>. Fast enough to execute within <strong>10 ms </strong>can be considered a good test,</p>



<p></p>



<p><strong>Why? What does </strong>it really mean<strong> to Developer? See below,</strong></p>



<p></p>



<ul class="wp-block-list">
<li>Build your method/functions as small as possible.</li>
</ul>



<ul class="wp-block-list">
<li>If method/functions exist already, refactor it immediately (pretty simple to say but go and get in buy-in from your Manager 🙂 for refactoring the code)</li>
</ul>



<ul class="wp-block-list">
<li>Small functions are easier to test and maintain.</li>
</ul>



<ul class="wp-block-list">
<li>Small functions promote reading and reuse.</li>
</ul>



<ul class="wp-block-list">
<li>Small functions help avoid hidden bugs that come with large functions. Large functions are sometimes impossible to test due to large dependencies and affect badly on code coverage.</li>
</ul>



<p></p>



<p>So this best practice really has a broader meaning which drives all goodies to your code. </p>



<p></p>



<p>Do Not Stop here &#8230;Here is what will make you think to design a better method/function if you are following<strong> Test Driven Development (TDD)</strong> or even make you think redesign/refactoring your existing legacy code.</p>



<p></p>



<blockquote class="wp-block-quote is-style-large is-layout-flow wp-block-quote-is-layout-flow">
<p><strong>2. Unit test cases should be isolated </strong></p>



<p></p>
</blockquote>



<ul class="wp-block-list">
<li>Unit test cases are meant only for a given function and its business logic in a given class.</li>
</ul>



<ul class="wp-block-list">
<li>If that <strong>method/functions</strong> (Let&#8217;s say <strong>A() </strong>)calls any other<strong> method/functions</strong> ( let&#8217;s say <strong>B()</strong>)then you write separate unit tests for that dependency(i.e <strong>B()</strong>). That means you need to mock <strong>B() </strong>within <strong>A() </strong>to make isolation.</li>
</ul>



<ul class="wp-block-list">
<li>Each unit test should be stateless and doesn&#8217;t depend on other unit tests by any means.</li>
</ul>



<p></p>



<blockquote class="wp-block-quote is-style-large is-layout-flow wp-block-quote-is-layout-flow">
<p><strong>3. Unit Test cases should be Repeatable.</strong></p>
</blockquote>



<p></p>



<ul class="wp-block-list">
<li>This lot more depend on the second principle i.e Unit test cases are isolated.</li>
</ul>



<ul class="wp-block-list">
<li>You get the same result for any number of times test cases are executed.</li>
</ul>



<ul class="wp-block-list">
<li>You get the same result for any order in which test cases are executed as they are stateless in nature.</li>
</ul>



<ul class="wp-block-list">
<li>That means you get the same result for all reasons except when breaking changes introduced by developers.</li>
</ul>



<ul class="wp-block-list">
<li>Unit test cases find breaking changes right ahead of time.</li>
</ul>



<p></p>



<blockquote class="wp-block-quote is-style-large is-layout-flow wp-block-quote-is-layout-flow">
<p></p>



<p><strong>4. Unit test cases should be Self Checking.</strong></p>
</blockquote>



<p></p>



<ul class="wp-block-list">
<li>Already written unit test cases will be kept on checking for any breaking changes introduced by any developers.</li>
</ul>



<ul class="wp-block-list">
<li>Right ahead of time intimation of a new bug introduced in the code by failing Unit test cases.</li>
</ul>



<ul class="wp-block-list">
<li>Self-checking will work on the local machine or could work on the build server as part of the<strong> CI-CD</strong> pipeline.</li>
</ul>



<p></p>



<blockquote class="wp-block-quote is-style-large is-layout-flow wp-block-quote-is-layout-flow">
<p><strong>5. Unit test cases should be Timely</strong></p>



<p></p>
</blockquote>



<ul class="wp-block-list">
<li>A unit test should be written in a timely manner and should not take more time than the actual development of business functionality. </li>
</ul>



<ul class="wp-block-list">
<li>Convinced? Here are the questions clarifying how much time should be spent on Unit test writing.</li>
</ul>



<p></p>



<p><strong><em>If your unit test is taking more time to write,</em></strong></p>



<p></p>



<ul class="wp-block-list">
<li>That means you need to follow the first principle concept very seriously.</li>
</ul>



<ul class="wp-block-list">
<li>Method/functions is not small enough to test all scenarios easily.</li>
</ul>



<ul class="wp-block-list">
<li>Need to design/refactor your class, method/functions.</li>
</ul>



<ul class="wp-block-list">
<li>That means need to pitch in hard negotiating on Design..and lastly, do not stop here .. go get the buy-in.</li>
</ul>



<p></p>



<p>Unit test cases have <strong><em>+ ve impact</em></strong> in the long run and do provide a lot of benefits on the maintenance side (<strong><em>shift left)</em></strong> for early identification of bugs and issues. </p>



<p></p>



<p>If working on existing code, unit test cases will give you a lot of early signals of coding issues and opportunities for improvements. </p>



<p></p>



<p>It&#8217;s important to implement all those if possible.</p>



<p></p>



<p>Remember maintenance is a big fat elephant and always eats away most of the project budget in <strong><em>SDLC</em></strong>.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-some-additional-best-practices-and-guidelines-for-unit-test-cases">Some additional best practices and guidelines for Unit Test cases,</h2>



<p></p>



<ul class="wp-block-list">
<li>Test only public members. These public members can be used to test private members implicitly.</li>
</ul>



<ul class="wp-block-list">
<li>Name your test appropriately. Please visit for naming conventions :
<ul class="wp-block-list">
<li><em><a href="https://www.thecodebuzz.com/tdd-unit-testing-naming-conventions-and-standards/" target="_blank" rel="noreferrer noopener"><strong>Unit Testing Naming Conventions and Standards</strong></a></em></li>
</ul>
</li>
</ul>



<p></p>



<ul class="wp-block-list">
<li>Do not test auto-generated code-Example &#8211; Entity framework scaffolding, WSDL generated proxy class members, etc.</li>
</ul>



<ul class="wp-block-list">
<li>Create stateless unit test cases. </li>
</ul>



<ul class="wp-block-list">
<li>The order of execution of unit test cases is not important.</li>
</ul>



<ul class="wp-block-list">
<li>Use code coverage tools for measuring code coverage.</li>
</ul>



<ul class="wp-block-list">
<li>Mock everything which is a dependency.</li>
</ul>



<ul class="wp-block-list">
<li>Interface-based programming favors unit test cases. Always program by abstraction.</li>
</ul>



<ul class="wp-block-list">
<li>Use Test-driven development with the Test first approach.</li>
</ul>



<ul class="wp-block-list">
<li>Do not test private members/functions/methods. Try testing them using the public method instead.</li>
</ul>



<p></p>



<p><strong><em>References </em></strong>:</p>



<p></p>



<ul class="has-medium-font-size wp-block-list">
<li><em><a href="https://www.thecodebuzz.com/tdd-unit-testing-naming-conventions-and-standards/" target="_blank" rel="noreferrer noopener">TDD – Unit Testing Naming Conventions and Standards</a></em></li>
</ul>



<ul class="has-medium-font-size wp-block-list">
<li><em><a href="https://www.thecodebuzz.com/integration-testing-best-practices-agile/" target="_blank" rel="noreferrer noopener" title="Integration Testing Best Practices in Agile">What is IntegrationTesting</a></em></li>
</ul>



<ul class="has-medium-font-size wp-block-list">
<li><a href="https://www.thecodebuzz.com/top-10-benefits-of-unit-testing-awesome-code/" target="_blank" rel="noopener" title="Top 10 Benefits of Unit Testing – Awesome Code"><em>Top 10 Benefits of Unit Testing – Awesome Code</em></a></li>
</ul>



<p></p>



<p style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size"></p>



<p style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size"></p>



<p class="has-medium-font-size"><strong>Happy Coding </strong>!!</p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p>



<p> </p><p>The post <a href="https://thecodebuzz.com/unit-testing-best-practices/">Unit Test Best Practices in Code Development</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/unit-testing-best-practices/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>How to Order Test cases &#8211; Guidelines</title>
		<link>https://thecodebuzz.com/order-unit-test-cases-or-integration-testing-guidelines/</link>
					<comments>https://thecodebuzz.com/order-unit-test-cases-or-integration-testing-guidelines/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 14 Jul 2021 05:49:00 +0000</pubDate>
				<category><![CDATA[Automation Testing]]></category>
		<category><![CDATA[how to write a test case]]></category>
		<category><![CDATA[how to write functional test cases]]></category>
		<category><![CDATA[how to write test cases for fresher]]></category>
		<category><![CDATA[how to write test cases in excel sheet]]></category>
		<category><![CDATA[how to write test cases in manual testing]]></category>
		<category><![CDATA[test cases example]]></category>
		<category><![CDATA[what is test case in manual testing]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=17079</guid>

					<description><![CDATA[<p>How to Order Test cases &#8211; Guidelines Today&#8217;s article demonstrates how to Order Test cases execution using a testing framework. Today in this article, We shall cover this requirements using Test frameworks like MSTest, xUnit, and NUnit. We will cover below aspects of test case ordering in today&#8217;s article, As a good practice, we generally [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/order-unit-test-cases-or-integration-testing-guidelines/">How to Order Test cases – Guidelines</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading"><strong>How to Order Test cases &#8211; Guidelines</strong></h1>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="391" src="https://www.thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-1024x391.jpg" alt="Order Unit Test case" class="wp-image-17534" srcset="https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-1024x391.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-300x115.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-768x293.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-1536x587.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-2048x783.jpg 2048w, https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-785x300.jpg 785w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>Today&#8217;s article demonstrates how to Order Test cases execution using a testing framework. Today in this article, We shall cover this requirements using Test frameworks like <strong><em>MSTest, xUnit, and NUnit</em></strong>.</p>



<p></p>



<p>We will cover below aspects of test case ordering in today&#8217;s article,</p>



<p></p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-understanding-itestcaseorderer-interface">Understanding ITestCaseOrderer interface</a></li><li><a href="#aioseo-xunit-test-case-order-by-priority---custom-attribute">XUnit Test case Order by Priority &#8211; custom attribute</a></li><li><a href="#aioseo-order-xunit-test-cases-by-alphabetical-order">Order Test cases in Alphabetical Order</a></li><li><a href="#aioseo-order-xunit-test-cases-by-collection-name-order">Order XUnit test cases by Collection Name Order</a></li></ul></div>



<p></p>



<p>As a good practice, we generally don&#8217;t order Unit test cases, because we always create them as <em><strong>stateless </strong></em>as possible and each unit test should run independently of each other. </p>



<p>But test case execution orders using <strong><em>Alphabetical </em></strong>or <strong><em>Display names</em></strong> still can be used for <strong><em>UnitTest </em></strong>cases if needed for better organizing the Test cases. </p>



<p></p>



<p><strong><em>Priority</em></strong> orders can be used for functional test cases or Integration test cases where we need to perform the operation in certain orders.</p>



<p></p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>This could be legitimate use cases for <strong><em>Integration test cases  and Functional Test cases</em></strong> . When you are dealing with the testing of various workflow and functional scenarios it might be necessary to plan certain action in an order ex.by <strong><em>Priority </em></strong>order to execute the business workflow.</p><p></p><p><em><strong>Example: Transcation in Banking </strong></em></p><p></p><p><em><span class="has-inline-color has-vivid-cyan-blue-color">1.Login to Login page of Banking website</span></em></p><p><em><span class="has-inline-color has-vivid-cyan-blue-color">2.Showing default summary page</span></em></p><p><em><span class="has-inline-color has-vivid-cyan-blue-color">3.Performing fund transfer </span></em></p><p><em><span class="has-inline-color has-vivid-cyan-blue-color">4.Veryfing balance </span></em></p></blockquote>



<p></p>



<p>Ordering on test cases can be achieved by any of the below mechanisms,</p>



<p></p>



<ul class="wp-block-list"><li><strong>Alphabetical </strong>&#8211; Order test method based on test name&#8217;s Alphabetical order</li></ul>



<ul class="wp-block-list"><li><strong>DisplayName </strong>&#8211; Order test method based on test name&#8217;s DisplayName order</li></ul>



<ul class="wp-block-list"><li><strong>Priority</strong>&#8211; Order test method based on test name&#8217;s using priority order set by the user providing better control on execution.</li></ul>



<p></p>



<h2 class="wp-block-heading" id="aioseo-understanding-itestcaseorderer-interface">Understanding ITestCaseOrderer interface</h2>



<p></p>



<ul class="wp-block-list"><li><strong>ITestCaseOrderer </strong>is the user interface provided by the XUnit ordering the execution of test cases. A class implements this interface to participate in ordering tests for the test runner. </li></ul>



<ul class="wp-block-list"><li>Test case orderers are applied using the <strong><em>Xunit.TestCaseOrdererAttribute</em></strong>.</li></ul>



<ul class="wp-block-list"><li>Test case orderer can be applied at the below level, <ul><li>Assembly, </li><li>Test collection</li><li>Test class level.</li></ul></li></ul>



<p></p>



<h2 class="wp-block-heading" id="aioseo-xunit-test-case-order-by-priority---custom-attribute">XUnit Test case Order by Priority &#8211; custom attribute</h2>



<p></p>



<p>To order xUnit tests with custom attributes like below we have used <strong><em>TestPriority</em></strong>. </p>



<p></p>



<p>Define a&nbsp;<strong><em><code>TestPriorityAttribute</code> </em></strong>and PriorityOrderer&nbsp;as follows.</p>



<p></p>



<p>Please see below an example of <strong><em>TestPriorityAttribute </em></strong>definition.</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [1]; title: ; notranslate">
    
    &#x5B;AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
    public class TestPriorityAttribute : Attribute
    {
        public int Priority { get; private set; }

        public TestPriorityAttribute(int priority) =&gt; Priority = priority;
    }

</pre></div>


<p></p>



<p><strong><em>PriorityOrderer</em></strong> class is defined as below using <em><strong>ITestCaseOrderer</strong></em></p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; title: ; notranslate">
 
public class PriorityOrderer : ITestCaseOrderer
    {

        public IEnumerable&lt;TTestCase&gt; OrderTestCases&lt;TTestCase&gt;(
            IEnumerable&lt;TTestCase&gt; testCases) where TTestCase : ITestCase
        {
            string assemblyName = typeof(TestPriorityAttribute).AssemblyQualifiedName!;
            var sortedMethods = new SortedDictionary&lt;int, List&lt;TTestCase&gt;&gt;();
            foreach (TTestCase testCase in testCases)
            {
                int priority = testCase.TestMethod.Method
                    .GetCustomAttributes(assemblyName)
                    .FirstOrDefault()
                    ?.GetNamedArgument&lt;int&gt;(nameof(TestPriorityAttribute.Priority)) ?? 0;

                GetOrCreate(sortedMethods, priority).Add(testCase);
            }

            foreach (TTestCase testCase in
                sortedMethods.Keys.SelectMany(
                    priority =&gt; sortedMethods&#x5B;priority].OrderBy(
                        testCase =&gt; testCase.TestMethod.Method.Name)))
            {
                yield return testCase;
            }
        }

        private static TValue GetOrCreate&lt;TKey, TValue&gt;(
            IDictionary&lt;TKey, TValue&gt; dictionary, TKey key)
            where TKey : struct
            where TValue : new() =&gt;
            dictionary.TryGetValue(key, out TValue result)
                ? result
                : (dictionary&#x5B;key] = new TValue());
    }
</pre></div>


<p></p>



<p>Once you define the classes above, Attribute your test class with the&nbsp;<code>TestCaseOrdererAttribute</code>&nbsp;to the&nbsp;<code>PriorityOrderer</code>.</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [1,8]; title: ; notranslate">
    &#x5B;TestCaseOrderer(&quot;OrechstrationService.Project.Orderers.PriorityOrderer&quot;, &quot;OrechstrationService.Project&quot;)]
    public class HttpHelperTests
    {
        public static bool Test1Called;
        public static bool Test2Called;
        public static bool Test3Called;  

        &#x5B;Fact, TestPriority(3)]
        public async Task AccountController_OnGetAccount_Valid_HTTPClient()
        { 
            //Arrange
          
            //Act

            //Assert
            Test3Called = true;
            Assert.True(Test1Called);
            Assert.True(Test2Called);
        
        }
    }


</pre></div>


<p></p>



<p>Below are examples of other unit test cases which execute based on priority.</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [1,16]; title: ; notranslate">
        &#x5B;Fact, TestPriority(2)]
        public async Task AccountController_OnGetAccount_Valid_HTTPClientFactory()
        {
            //Arrange
          
            //Act

            //Assert
            Test2Called = true;
            Assert.True(Test1Called);
            Assert.False(Test3Called);

        }


        &#x5B;Fact, TestPriority(1)]
        public async void AccountController_OnGetAccount_Valid_Typed_HTTPClient()
        {

           //Arrange
          
            //Act

            //Assert
            Test1Called = true;
            Assert.False(Test2Called);
            Assert.False(Test1Called);
        }
</pre></div>


<p></p>



<p>With the above arrangements now once we execute the test cases, we shall see test cases are getting executed based on the priority set.</p>



<p></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="236" src="https://www.thecodebuzz.com/wp-content/uploads/2021/07/Order-Unit-test-casee-Xunit-MsTest-nUnit-1024x236.jpg" alt="" class="wp-image-17513" srcset="https://thecodebuzz.com/wp-content/uploads/2021/07/Order-Unit-test-casee-Xunit-MsTest-nUnit-1024x236.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/07/Order-Unit-test-casee-Xunit-MsTest-nUnit-300x69.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/07/Order-Unit-test-casee-Xunit-MsTest-nUnit-768x177.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/07/Order-Unit-test-casee-Xunit-MsTest-nUnit-1536x354.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/07/Order-Unit-test-casee-Xunit-MsTest-nUnit-785x181.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2021/07/Order-Unit-test-casee-Xunit-MsTest-nUnit.jpg 1925w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<p></p>



<p>Alternatively &#8211; <strong><em>Assert </em></strong>statements for the above 3 Tests using Test1Called, Test2Called, and Test3Called also confirm the order of the execution is correct.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-order-xunit-test-cases-by-alphabetical-order"><strong>Order Test cases in Alphabetical Order</strong></h2>



<p></p>



<p>Implement the <code>ITestCaseOrderer</code> and provide an ordering mechanism. With this, we will order the Test cases using the <strong><em>method name</em></strong>.</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; title: ; notranslate">
using System.Collections.Generic;
using System.Linq;
using Xunit.Abstractions;
using Xunit.Sdk;

namespace OrechstrationService.Project
{
    public class AlphabeticalOrderer : ITestCaseOrderer
    {
        public IEnumerable&lt;TTestCase&gt; OrderTestCases&lt;TTestCase&gt;(
            IEnumerable&lt;TTestCase&gt; testCases) where TTestCase : ITestCase =&gt;
            testCases.OrderBy(testCase =&gt; testCase.TestMethod.Method.Name);
    }


}
</pre></div>


<p></p>



<p><strong><em>TestCaseOrderer </em></strong>now can be defined using  <strong><em>AlphabeticalOrderer </em></strong>as below,</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [1]; title: ; notranslate">
   &#x5B;TestCaseOrderer(&quot;OrechstrationService.Project.Orderers.AlphabeticalOrderer&quot;, &quot;OrechstrationService.Project&quot;)]

    public class HttpHelperTests
    {
        public static bool Test1Called;
        public static bool Test2Called;
        public static bool Test3Called;  

        &#x5B;Fact]
        public async Task AccountController_OnGetAccount_Valid_HTTPClient()
        { 
            //Arrange
          
            //Act

            //Assert
            Test3Called = true;
            Assert.True(Test1Called);
            Assert.True(Test2Called);
        
        }
        &#x5B;Fact]
        public async Task AccountController_OnGetAccount_Valid_HTTPClientFactory()
        {
            //Arrange
          
            //Act

            //Assert
            Test2Called = true;
            Assert.True(Test1Called);
            Assert.False(Test3Called);

        }


        &#x5B;Fact]
        public async void AccountController_OnGetAccount_Valid_Typed_HTTPClient()
        {

           //Arrange
          
            //Act

            //Assert
            Test1Called = true;
            Assert.False(Test2Called);
            Assert.False(Test3Called);
        }

}

</pre></div>


<p></p>



<p>Once executed you can see test cases are now run based on the method name,</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="246" src="https://www.thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-by-alphabetical-order-1024x246.jpg" alt="Order XUnit test cases by Alphabetical Order" class="wp-image-17546" srcset="https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-by-alphabetical-order-1024x246.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-by-alphabetical-order-300x72.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-by-alphabetical-order-768x185.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-by-alphabetical-order-1536x369.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-by-alphabetical-order-785x189.jpg 785w, https://thecodebuzz.com/wp-content/uploads/2021/08/ordered-test-cases-by-alphabetical-order.jpg 1821w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<h2 class="wp-block-heading" id="aioseo-order-xunit-test-cases-by-collection-name-order">Order XUnit test cases by Collection Name Order</h2>



<p></p>



<p>Please see the below article for more details,</p>



<p></p>



<ul class="wp-block-list"><li><strong><em><a href="https://www.thecodebuzz.com/xunit-test-case-order-by-display-name/" target="_blank" rel="noreferrer noopener" title="XUnit Test case Order by Display Name">XUnit Test case Order by Display Name</a></em></strong></li></ul>



<p></p>



<p></p>



<p><strong><em>References: </em></strong></p>



<p></p>



<ul class="wp-block-list"><li><a href="https://www.thecodebuzz.com/data-driven-testing-in-net-core/" title="Data-Driven Testing in .NET Core" target="_blank" rel="noreferrer noopener"><strong><em>Data-Driven Testing in .NET Core</em></strong></a></li></ul>



<p></p>



<p></p>



<p style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size"></p>



<p style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size"></p>



<p class="has-medium-font-size"><strong>Happy Coding </strong>!!</p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p>



<p></p><p>The post <a href="https://thecodebuzz.com/order-unit-test-cases-or-integration-testing-guidelines/">How to Order Test cases – Guidelines</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/order-unit-test-cases-or-integration-testing-guidelines/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
