{"id":16537,"date":"2024-05-30T06:50:30","date_gmt":"2024-05-30T06:50:30","guid":{"rendered":"https:\/\/positiwise.com\/blog\/?p=16537"},"modified":"2024-05-30T09:06:54","modified_gmt":"2024-05-30T09:06:54","slug":"unit-tests-in-net-core","status":"publish","type":"post","link":"https:\/\/positiwise.com\/blog\/unit-tests-in-net-core","title":{"rendered":"Setting Up and Writing Unit Tests in .NET Core"},"content":{"rendered":"\n<p><strong class=\"pw-highlight-text-color\"><em>Quick Overview:<\/em><\/strong><br>A practical approach is followed in the blog to help you understand setting up and writing unit tests in .NET Core. MSTest framework is utilized to demonstrate the process along with their expected output. By following the curated content, you can gain detailed insight into the .NET core unit test scenarios that can help you with real-world projects.<\/p><div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#A_Run-Through_NET_Core_vs_Nodejs\" >A Run-Through: .NET Core vs Node.js<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#NET_Core\" >.NET Core<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Pros_of_using_NET_Core\" >Pros of using .NET Core<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Nodejs\" >Node.js<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#A_Deep_Dive_into_NET_Core_vs_Nodejs\" >A Deep Dive into .NET Core vs. Node.js<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Processing_Approach_and_Performance\" >Processing Approach and Performance<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Security\" >Security<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Scalability\" >Scalability<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Platform_Adaptability\" >Platform Adaptability<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Support_from_Community\" >Support from Community<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Comparison_Table_between_NET_Core_and_Nodejs\" >Comparison Table between .NET Core and Node.js<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\/#Wrapping_Up_on_NET_Core_vs_Nodejs\" >Wrapping Up on .NET Core vs Node.js<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-writing-unit-tests-in-net-core\">Writing Unit Tests in .NET Core<\/h2>\n\n\n\n<p>In a software development lifecycle, not only testers but also <a href=\"https:\/\/positiwise.com\/hire-asp-net-developers\">.NET developers<\/a> validate the application\u2019s working. The development team conducts .NET core unit tests, which help them remove bugs and forward a high-performing, issue-free, and secure application.<\/p>\n\n\n\n<p>The entire procedure for unit testing is quite streamlined. Here, we have provided the complete practical process to help you with writing .NET unit test cases according to your requirements and convenience.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-net-core-unit-test-what-and-why\">.NET Core Unit Test: What and Why?<\/h2>\n\n\n\n<p>Whenever a .NET Core application is developed, it goes under numerous testing procedures. But, before handing the app to testers, .NET developers test the application on their end, and it&#8217;s known as .NET Core unit tests.<\/p>\n\n\n\n<p>In unit testing, multiple test cases are created, and a test framework is utilized. The main aim of developer testing the software is to find and resolve the bugs, issues, and exceptions. In addition, it also aids in reducing the tester&#8217;s workload and releasing the app as per the defined schedule.<\/p>\n\n\n\n<p>Moreover, unit testing benefits with:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Improving code quality.<\/li>\n\n\n\n<li>Early-stage bug detection.<\/li>\n\n\n\n<li>Enhancing code reusability and accelerating deployment.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-frameworks-utilized-for-net-core-unit-test-purposes\">Frameworks Utilized For .NET Core Unit Test Purposes<\/h2>\n\n\n\n<p>In .NET Core, the following three frameworks are mostly utilized by a .NET development company to verify the functioning of the application.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>MSTest<\/li>\n\n\n\n<li>NUnit<\/li>\n\n\n\n<li>xUnit<\/li>\n<\/ul>\n\n\n\n<p>All these frameworks are used for a similar purpose, that is, to write test cases. The only difference between the frameworks is their syntax, features, and core functionalities. However, when it comes to MSTest, no other technology can match it in terms of testing the <a href=\"https:\/\/positiwise.com\/technologies\/dot-net-development\">.NET core application<\/a>.<\/p>\n\n\n\n<p>MSTest is the official framework from Microsoft that is, by default, integrated as a core feature of Visual Studio IDE. It\u2019s considered as a high-end testing framework that works seamlessly with .NET CLI and numerous CI pipelines. In addition, it supports all .NET targets, including .NET Core, UWP, WinUI, .NET Framework, and more.<\/p>\n\n\n\n<p>On the other hand, <a href=\"https:\/\/positiwise.com\/blog\/unit-testing-in-net-core-using-nunit\">NUnit<\/a> and xUnit are also considered reliable testing frameworks. However, they are only preferred if additional testing is required. Otherwise, MSTest is enough for .NET core unit tests.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-to-unit-tests-in-net-core-a-practical-approach\">How To Unit Tests in .NET Core: A Practical Approach<\/h2>\n\n\n\n<p>Here, we are going to use the MSTest framework to test the .NET Core application. To start with the practical tutorial, you need Visual Studio, which will help you create an Asp.net web app. Also, we are going to name the project &#8220;UnitTestDemo&#8221; for this tutorial.<\/p>\n\n\n\n<p>Once your project is created, follow the below steps.<\/p>\n\n\n\n<p><strong>Step 1:<\/strong> Go under the solution explorer section and generate a new service class with the name &#8220;MessageService.cs&#8221;.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"530\" height=\"570\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Messageservice.cs_-jpg.webp\" alt=\"generate a new service class with the name MessageService.cs\" class=\"wp-image-16538\" style=\"width:499px;height:auto\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Messageservice.cs_-jpg.webp 530w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Messageservice.cs_-279x300.webp 279w\" sizes=\"auto, (max-width: 530px) 100vw, 530px\" \/><\/figure>\n\n\n\n<p>After the service class creation, add the below code to return a message using the string data type.<\/p>\n\n\n\n<pre class=\"wp-block-code alignwide\"><code>using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Threading.Tasks;\n\nnamespace UnitTestDemo.Services\n{\n    public class MessageService\n    {\n        public Func&lt;string> msg1 = () => \"Hello there!\";\n        public Func&lt;string> msg2 = () => \"Good Morning!\";        \n    }\n}<\/code><\/pre>\n\n\n\n<p><strong>Step 2:<\/strong> Add the MSTest library to the project. To do this, follow the below path.<\/p>\n\n\n\n<p>Solution -> Add -> Add new project -> Select project -> MSTest Test project.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"531\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/MS-unit-Test-Library-1024x531-1-jpg.webp\" alt=\"add new project by selecting project and then MSTest Test Project\" class=\"wp-image-16539\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/MS-unit-Test-Library-1024x531-1-jpg.webp 1024w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/MS-unit-Test-Library-1024x531-1-300x156.webp 300w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/MS-unit-Test-Library-1024x531-1-768x398.webp 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Check the solutions explorer section to ensure that MSTest is added. The output will look similar to the following snippet.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"529\" height=\"629\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/MessageTest.cs_-jpg.webp\" alt=\"ensure if MSTest is added\" class=\"wp-image-16542\" style=\"width:393px;height:auto\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/MessageTest.cs_-jpg.webp 529w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/MessageTest.cs_-252x300.webp 252w\" sizes=\"auto, (max-width: 529px) 100vw, 529px\" \/><\/figure>\n\n\n\n<p><strong>Step 3:<\/strong> Add the &#8220;UnitTestDemo&#8221; project reference to &#8220;TestDemo&#8221; to use the methods defined in the &#8220;MessageService.cs&#8221; file.<\/p>\n\n\n\n<p>In addition, add a test class to the \u201cMessageService.cs\u201d file. Copy the following code to the file. There are two test methods that will validate the &#8220;MessageService.cs&#8221; file methods. In addition, \u201c[TestClass]\u201d is used for annotating class, and \u201c[TestMethod]\u201d is used to annotate test methods.<\/p>\n\n\n\n<p>Moreover, an assert method is also included to help you detect errors and resolve them in the production environment.<\/p>\n\n\n\n<pre class=\"wp-block-code alignwide\"><code>using Microsoft.VisualStudio.TestTools.UnitTesting;\nusing UnitTestDemo.Services;\n\nnamespace TestDemo\n{\n    &#91;TestClass]\n    public class MessageTest\n    {\n        private const string Expected1 = \"Hello there! Test!!!\";\n        private const string Expected2 = \"Good Morning!\";\n\n        MessageService message = new MessageService();\n\n        &#91;TestMethod]\n        public void Message1()\n        {\n            var m1 = message.msg1();\n\n            Assert.AreEqual(Expected1, m1);\n        }\n\n        &#91;TestMethod]\n        public void Message2()\n        {\n            var m2 = message.msg2();\n\n            Assert.AreEqual(Expected2, m2);\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong>Step 4:<\/strong> Now, run the tests to see how MSTest works.<\/p>\n\n\n\n<p>In the solution explorer, you\u2019ll find \u201cMessageTest.cs\u201d under the TestDemo. You have to right-click on it and hit the &#8220;Run Tests&#8221; option.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"521\" height=\"769\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Select-Run-Tests-jpg.webp\" alt=\"Run Test\" class=\"wp-image-16547\" style=\"width:495px;height:auto\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Select-Run-Tests-jpg.webp 521w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Select-Run-Tests-203x300.webp 203w\" sizes=\"auto, (max-width: 521px) 100vw, 521px\" \/><\/figure>\n\n\n\n<p><strong>Step 5:<\/strong> Following the &#8220;Run Tests&#8221; click, the test methods will initiate their execution to verify the working of service methods. You will see the entire output on your screen, just like the snippet below.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"811\" height=\"598\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Run-Tests-Passed-jpg.webp\" alt=\"Run Test Passed\" class=\"wp-image-16548\" style=\"width:564px;height:auto\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Run-Tests-Passed-jpg.webp 811w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Run-Tests-Passed-300x221.webp 300w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Run-Tests-Passed-768x566.webp 768w\" sizes=\"auto, (max-width: 811px) 100vw, 811px\" \/><\/figure>\n\n\n\n<p>As you can see above, a total of two tests were conducted, and the application passed them both. Further, if you modify the code, the output will also change accordingly.<\/p>\n\n\n\n<p>We have completed the fundamentals of testing with MSTest. But now, we are going to modify some conditions and view the results.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-scenario-1-parameterized-test\"><strong>Scenario #1: Parameterized Test<\/strong><\/h3>\n\n\n\n<p><strong>1st Step: <\/strong>Create a new service file (\u201cArithService.cs) under \u201cUnitTestDemo\u201d -> Services.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"487\" height=\"730\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Arithservice.cs_-jpg.webp\" alt=\"Create a new service file as ArithService.cs under UnitTestDemo\" class=\"wp-image-16553\" style=\"width:454px;height:auto\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Arithservice.cs_-jpg.webp 487w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Arithservice.cs_-200x300.webp 200w\" sizes=\"auto, (max-width: 487px) 100vw, 487px\" \/><\/figure>\n\n\n\n<p><strong>2nd Step:<\/strong> Add the code to the &#8220;ArithService.cs&#8221; file.<\/p>\n\n\n\n<pre class=\"wp-block-code alignwide\"><code>using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Threading.Tasks;\n\nnamespace UnitTestDemo.Services\n{\n    public class ArithService\n    {\n        public Func&lt;int, int, int> add = (a, b) => a + b;\n        public Func&lt;int, int, int> mul = (a, b) => a * b;\n        public Func&lt;int, int, int> sub = (a, b) => a - b;\n        public Func&lt;int, int, int> div = (a, b) => a \/ b;\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong>3rd Step: <\/strong>Generate a new test case with the name &#8220;MessageTest.cs&#8221;. Further, add the following code to the &#8220;ArithTest.cs&#8221; file. The code includes the test methods for validating the functionalities.<\/p>\n\n\n\n<pre class=\"wp-block-code alignwide\"><code>using Microsoft.VisualStudio.TestTools.UnitTesting;\nusing UnitTestDemo.Services;\n\nnamespace TestDemo\n{\n    &#91;TestClass]\n    public class ArithTest\n    {\n        ArithService arith = new ArithService();\n\n        &#91;DataTestMethod]\n        &#91;DataRow(1, 2, 3)]\n        &#91;DataRow(2, 2, 4)]\n        &#91;DataRow(-1, 4, 3)]\n        public void Add(int x, int y, int expected)\n        {\n            int r = arith.add(x, y);\n            Assert.AreEqual(r, expected);\n        }\n\n        &#91;DataTestMethod]\n        &#91;DataRow(1, 2, -1)]\n        &#91;DataRow(2, 2, 0)]\n        &#91;DataRow(3, 2, 1)]\n        public void Sub(int x, int y, int expected)\n        {\n            int r = arith.sub(x, y);\n            Assert.AreEqual(r, expected);\n        }\n\n        &#91;DataTestMethod]\n        &#91;DataRow(9, 3, 27)]\n        &#91;DataRow(3, 3, 9)]\n        &#91;DataRow(-3, -3, 9)]\n        &#91;Ignore]\n        public void Mul(int x, int y, int expected)\n        {\n            int r = arith.mul(x, y);\n            Assert.AreEqual(r, expected);\n        }\n\n        &#91;DataTestMethod]\n        &#91;DataRow(9, 3, 3)]\n        &#91;DataRow(3, 3, 1)]\n        &#91;DataRow(8, 2, 4)]\n        &#91;Ignore]\n        public void Div(int x, int y, int expected)\n        {\n            int r = arith.div(x, y);\n            Assert.AreEqual(r, expected);\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong>4th Step:<\/strong> Lastly, test the service. The code we added will utilize three different values to calculate the output and provide relevant test results.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"845\" height=\"492\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Assert.Are-Equal-jpg.webp\" alt=\"output for scenario 1\n\" class=\"wp-image-16556\" style=\"width:752px;height:auto\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Assert.Are-Equal-jpg.webp 845w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Assert.Are-Equal-300x175.webp 300w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Assert.Are-Equal-768x447.webp 768w\" sizes=\"auto, (max-width: 845px) 100vw, 845px\" \/><\/figure>\n\n\n\n<p>As you can see, all three values passed using the test methods passed the testing case.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-scenario-2-skipping-tests\"><strong>Scenario #2: Skipping Tests<\/strong><\/h3>\n\n\n\n<p>In case you want to skip some methods from the test. To do so, MSTest offers the functionality of the [Ignore] attribute.<\/p>\n\n\n\n<p>To understand its functionality, replace the code used in the previous test case with the following one, including the [Ignore] attribute.<\/p>\n\n\n\n<pre class=\"wp-block-code alignwide\"><code>using System.Collections.Generic;\nusing Microsoft.VisualStudio.TestTools.UnitTesting;\nusing UnitTestDemo.Services;\n\nnamespace TestDemo\n{\n    &#91;TestClass]\n    public class ArithDynamicDataTest\n    {\n        ArithService arith = new ArithService();\n\n        &#91;DataTestMethod]\n        &#91;DynamicData(nameof(AddData), DynamicDataSourceType.Method)]\n        public void Add(int x, int y, int expected)\n        {\n            int r = arith.add(x, y);\n            Assert.AreEqual(r, expected);\n        }\n\n        &#91;DataTestMethod]\n        &#91;DynamicData(nameof(SubData), DynamicDataSourceType.Method)]\n        public void Sub(int x, int y, int expected)\n        {\n            int r = arith.sub(x, y);\n            Assert.AreEqual(r, expected);\n        }\n\n        &#91;DataTestMethod]\n        &#91;DynamicData(nameof(MulData), DynamicDataSourceType.Method)]\n        public void Mul(int x, int y, int expected)\n        {\n            int r = arith.mul(x, y);\n            Assert.AreEqual(r, expected);\n        }\n\n        &#91;DataTestMethod]\n        &#91;DynamicData(nameof(DivData), DynamicDataSourceType.Method)]\n        public void Div(int x, int y, int expected)\n        {\n            int r = arith.div(x, y);\n            Assert.AreEqual(r, expected);\n        }\n\n        private static IEnumerable&lt;object&#91;]> AddData()\n        {\n            return new&#91;]\n            {\n            new object&#91;] { 1, 2, 3 },\n            new object&#91;] { 2, 2, 4 },\n            new object&#91;] { -1, 4, 3 }\n        };\n        }\n\n        private static IEnumerable&lt;object&#91;]> SubData()\n        {\n            return new&#91;]\n            {\n            new object&#91;] { 1, 2, -1 },\n            new object&#91;] { 2, 2, 0 },\n            new object&#91;] { 3, 2, 1 }\n        };\n        }\n\n        private static IEnumerable&lt;object&#91;]> MulData()\n        {\n            return new&#91;]\n            {\n            new object&#91;] { 9, 3, 27 },\n            new object&#91;] { 3, 3, 9 },\n            new object&#91;] { -3, -3, 9 }\n        };\n        }\n\n        private static IEnumerable&lt;object&#91;]> DivData()\n        {\n            return new&#91;]\n            {\n            new object&#91;] { 9, 3, 3 },\n            new object&#91;] { 3, 3, 1 },\n            new object&#91;] { 8, 2, 4 }\n        };\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p>Now, run the tests, and you&#8217;ll see that two tests are skipped, where we utilized the ignore attribute. The rest of the tests are passed.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"739\" height=\"312\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Ignore-attribute-jpg.webp\" alt=\"output for scenario 2\" class=\"wp-image-16557\" style=\"width:782px;height:auto\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Ignore-attribute-jpg.webp 739w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Ignore-attribute-300x127.webp 300w\" sizes=\"auto, (max-width: 739px) 100vw, 739px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-scenario-3-dynamic-data-testing\"><strong>Scenario #3: Dynamic Data Testing<\/strong><\/h3>\n\n\n\n<p>To write a test case for passing the dynamic data, the [DynamicData] attribute will be used with MSTest. It will help you pass the data from external sources to the defined methods to validate their work.<\/p>\n\n\n\n<p><strong>Step 1:<\/strong> Generate a new test file with the following code.<\/p>\n\n\n\n<pre class=\"wp-block-code alignwide\"><code>using System.Collections.Generic;\nusing Microsoft.VisualStudio.TestTools.UnitTesting;\nusing UnitTestDemo.Services;\n\nnamespace TestDemo\n{\n    &#91;TestClass]\n    public class ArithDynamicDataTest\n    {\n        ArithService arith = new ArithService();\n\n        &#91;DataTestMethod]\n        &#91;DynamicData(nameof(AddData), DynamicDataSourceType.Method)]\n        public void Add(int x, int y, int expected)\n        {\n            int r = arith.add(x, y);\n            Assert.AreEqual(r, expected);\n        }\n\n        &#91;DataTestMethod]\n        &#91;DynamicData(nameof(SubData), DynamicDataSourceType.Method)]\n        public void Sub(int x, int y, int expected)\n        {\n            int r = arith.sub(x, y);\n            Assert.AreEqual(r, expected);\n        }\n\n        &#91;DataTestMethod]\n        &#91;DynamicData(nameof(MulData), DynamicDataSourceType.Method)]\n        public void Mul(int x, int y, int expected)\n        {\n            int r = arith.mul(x, y);\n            Assert.AreEqual(r, expected);\n        }\n\n        &#91;DataTestMethod]\n        &#91;DynamicData(nameof(DivData), DynamicDataSourceType.Method)]\n        public void Div(int x, int y, int expected)\n        {\n            int r = arith.div(x, y);\n            Assert.AreEqual(r, expected);\n        }\n\n        private static IEnumerable&lt;object&#91;]> AddData()\n        {\n            return new&#91;]\n            {\n            new object&#91;] { 1, 2, 3 },\n            new object&#91;] { 2, 2, 4 },\n            new object&#91;] { -1, 4, 3 }\n        };\n        }\n\n        private static IEnumerable&lt;object&#91;]> SubData()\n        {\n            return new&#91;]\n            {\n            new object&#91;] { 1, 2, -1 },\n            new object&#91;] { 2, 2, 0 },\n            new object&#91;] { 3, 2, 1 }\n        };\n        }\n\n        private static IEnumerable&lt;object&#91;]> MulData()\n        {\n            return new&#91;]\n            {\n            new object&#91;] { 9, 3, 27 },\n            new object&#91;] { 3, 3, 9 },\n            new object&#91;] { -3, -3, 9 }\n        };\n        }\n\n        private static IEnumerable&lt;object&#91;]> DivData()\n        {\n            return new&#91;]\n            {\n            new object&#91;] { 9, 3, 3 },\n            new object&#91;] { 3, 3, 1 },\n            new object&#91;] { 8, 2, 4 }\n        };\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong>Step 2: <\/strong>Run the tests to view the output.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"726\" height=\"316\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Dynamic-dataattribute-jpg.webp\" alt=\"output for scenario 3\" class=\"wp-image-16558\" style=\"width:800px;height:auto\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Dynamic-dataattribute-jpg.webp 726w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Dynamic-dataattribute-300x131.webp 300w\" sizes=\"auto, (max-width: 726px) 100vw, 726px\" \/><\/figure>\n\n\n\n<p>As you can see in the output, the dynamic data has passed all the 16 tests. We haven&#8217;t used the [Ignore] attribute this time, so no test is skipped.<\/p>\n\n\n\n<p>Similarly, you can write your own test cases using MSTest to ensure that your application works efficiently and provides the correct output. \u00a0<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-wrapping-up\">Wrapping Up<\/h2>\n\n\n\n<p>.NET Core unit testing is streamlined with the help of available frameworks, such as MSTest, NUnit, and xUnit. You can utilize any of them to write test cases and verify the application functionality. But, according to professionals, MSTest is considered a reliable choice. By following the above process, MSTest can be utilized seamlessly to conduct parametrized, skip case, and dynamic input testing cases.<\/p>\n\n\n\n<p>Additionally, you can create your own <a href=\"https:\/\/positiwise.com\/technologies\/dot-net-development\">.NET Core<\/a> unit tests and ensure that your software works completely fine.<\/p>\n  <div class=\"related-post slider\">\r\n        <div class=\"headline\">Related Posts<\/div>\r\n    <div class=\"post-list owl-carousel\">\r\n\r\n            <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\".Net Core vs. Java \u2013 Which One You Should Use for Your Projects?\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-java-technology\">\r\n\r\n      <img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"800\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1.jpg\" class=\"attachment-full size-full wp-post-image\" alt=\".Net Core vs. Java \u2013 Which One You Should Use for Your Projects?\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1.jpg 1200w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1-300x200.jpg 300w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1-1024x683.jpg 1024w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1-768x512.jpg 768w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\".Net Core vs. Java \u2013 Which One You Should Use for Your Projects?\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-java-technology\">\r\n        .Net Core vs. Java \u2013 Which One You Should Use for Your Projects?  <\/a>\r\n\r\n        <\/div>\r\n              <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\"Precise Road Map for ASP.NET Developers\" href=\"https:\/\/positiwise.com\/blog\/roadmap-for-asp-dot-net-developers\">\r\n\r\n      <img loading=\"lazy\" decoding=\"async\" width=\"1021\" height=\"621\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1.jpg\" class=\"attachment-full size-full wp-post-image\" alt=\"Hire ASP.NET Developers - A Precise Road Map to Employ ASP.NET Developers\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1.jpg 1021w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1-300x182.jpg 300w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1-768x467.jpg 768w\" sizes=\"auto, (max-width: 1021px) 100vw, 1021px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\"Precise Road Map for ASP.NET Developers\" href=\"https:\/\/positiwise.com\/blog\/roadmap-for-asp-dot-net-developers\">\r\n        Precise Road Map for ASP.NET Developers  <\/a>\r\n\r\n        <\/div>\r\n              <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\".NET Core vs Node.js: The Difference Explained by Web Expert\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\">\r\n\r\n      <img loading=\"lazy\" decoding=\"async\" width=\"1021\" height=\"621\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/NET-Core-VS-Node-js-jpg.webp\" class=\"attachment-full size-full wp-post-image\" alt=\"NET-Core-VS-Node-js\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/NET-Core-VS-Node-js-jpg.webp 1021w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/NET-Core-VS-Node-js-300x182.webp 300w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/NET-Core-VS-Node-js-768x467.webp 768w\" sizes=\"auto, (max-width: 1021px) 100vw, 1021px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\".NET Core vs Node.js: The Difference Explained by Web Expert\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-node-js\">\r\n        .NET Core vs Node.js: The Difference Explained by Web Expert  <\/a>\r\n\r\n        <\/div>\r\n      \r\n  <\/div>\r\n\r\n  <script>\r\n      <\/script>\r\n  <style>\r\n    .related-post {}\r\n\r\n    .related-post .post-list {\r\n      text-align: left;\r\n          }\r\n\r\n    .related-post .post-list .item {\r\n      margin: 5px;\r\n      padding: 0px;\r\n          }\r\n\r\n    .related-post .headline {\r\n      font-size: 2rem !important;\r\n      color: #212529 !important;\r\n          }\r\n\r\n    .related-post .headline {\r\nmargin-top: 0;\r\npadding-left: 1%;\r\n}.related-post .post-list .item .post_thumb {\r\n      max-height: 220px;\r\n      margin: 0px 0px 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n          }\r\n\r\n    .related-post .post-list .item .post_title {\r\n      font-size: 1rem;\r\n      color: #212529;\r\n      margin: 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n      text-decoration: none;\r\n          }\r\n\r\n    .related-post .post-list .item .post_excerpt {\r\n      font-size: 13px;\r\n      color: #3f3f3f;\r\n      margin: 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n      text-decoration: none;\r\n          }\r\n\r\n    .related-post .owl-dots .owl-dot {\r\n          }\r\n\r\n      <\/style>\r\n      <script>\r\n      jQuery(document).ready(function($) {\r\n        $(\".related-post .post-list\").owlCarousel({\r\n          items: 3,\r\n          responsiveClass: true,\r\n          responsive: {\r\n            0: {\r\n              items: 1,\r\n            },\r\n            768: {\r\n              items: 2,\r\n            },\r\n            1200: {\r\n              items: 3,\r\n            }\r\n          },\r\n                      rewind: true,\r\n                                loop: true,\r\n                                center: true,\r\n                                autoplay: true,\r\n            autoplayHoverPause: true,\r\n                                nav: true,\r\n            navSpeed: 1000,\r\n            navText: ['<i class=\"fas fa-chevron-left\"><\/i>', '<i class=\"fas fa-chevron-right\"><\/i>'],\r\n                                dots: true,\r\n            dotsSpeed: 1200,\r\n                                                    rtl: false,\r\n          \r\n        });\r\n      });\r\n    <\/script>\r\n  <\/div>\r\n","protected":false},"excerpt":{"rendered":"<p>Quick Overview:A practical approach is followed in the blog to help you understand setting up and writing unit [&hellip;]<\/p>\n  <div class=\"related-post slider\">\r\n        <div class=\"headline\">Related Posts<\/div>\r\n    <div class=\"post-list owl-carousel\">\r\n\r\n            <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\".Net Core vs. Java \u2013 Which One You Should Use for Your Projects?\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-java-technology\">\r\n\r\n      <img width=\"1200\" height=\"800\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1.jpg\" class=\"attachment-full size-full wp-post-image\" alt=\".Net Core vs. Java \u2013 Which One You Should Use for Your Projects?\" decoding=\"async\" loading=\"lazy\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1.jpg 1200w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1-300x200.jpg 300w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1-1024x683.jpg 1024w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2021\/12\/web-security-partner-1-768x512.jpg 768w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\".Net Core vs. Java \u2013 Which One You Should Use for Your Projects?\" href=\"https:\/\/positiwise.com\/blog\/net-core-vs-java-technology\">\r\n        .Net Core vs. Java \u2013 Which One You Should Use for Your Projects?  <\/a>\r\n\r\n        <\/div>\r\n              <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\"Precise Road Map for ASP.NET Developers\" href=\"https:\/\/positiwise.com\/blog\/roadmap-for-asp-dot-net-developers\">\r\n\r\n      <img width=\"1021\" height=\"621\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1.jpg\" class=\"attachment-full size-full wp-post-image\" alt=\"Hire ASP.NET Developers - A Precise Road Map to Employ ASP.NET Developers\" decoding=\"async\" loading=\"lazy\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1.jpg 1021w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1-300x182.jpg 300w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/dealership-1200x800-1-768x467.jpg 768w\" sizes=\"auto, (max-width: 1021px) 100vw, 1021px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\"Precise Road Map for ASP.NET Developers\" href=\"https:\/\/positiwise.com\/blog\/roadmap-for-asp-dot-net-developers\">\r\n        Precise Road Map for ASP.NET Developers  <\/a>\r\n\r\n        <\/div>\r\n              <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\"A Descriptive Guide to .NET Framework\" href=\"https:\/\/positiwise.com\/blog\/a-descriptive-guide-to-dot-net-framework\">\r\n\r\n      <img width=\"1021\" height=\"621\" src=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/a-descriptive-guide-to-dot-net-framework.jpg\" class=\"attachment-full size-full wp-post-image\" alt=\"A Descriptive Guide to .NET Framework\" decoding=\"async\" loading=\"lazy\" srcset=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/a-descriptive-guide-to-dot-net-framework.jpg 1021w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/a-descriptive-guide-to-dot-net-framework-300x182.jpg 300w, https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2022\/01\/a-descriptive-guide-to-dot-net-framework-768x467.jpg 768w\" sizes=\"auto, (max-width: 1021px) 100vw, 1021px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\"A Descriptive Guide to .NET Framework\" href=\"https:\/\/positiwise.com\/blog\/a-descriptive-guide-to-dot-net-framework\">\r\n        A Descriptive Guide to .NET Framework  <\/a>\r\n\r\n        <\/div>\r\n      \r\n  <\/div>\r\n\r\n  <script>\r\n      <\/script>\r\n  <style>\r\n    .related-post {}\r\n\r\n    .related-post .post-list {\r\n      text-align: left;\r\n          }\r\n\r\n    .related-post .post-list .item {\r\n      margin: 5px;\r\n      padding: 0px;\r\n          }\r\n\r\n    .related-post .headline {\r\n      font-size: 2rem !important;\r\n      color: #212529 !important;\r\n          }\r\n\r\n    .related-post .headline {\r\nmargin-top: 0;\r\npadding-left: 1%;\r\n}.related-post .post-list .item .post_thumb {\r\n      max-height: 220px;\r\n      margin: 0px 0px 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n          }\r\n\r\n    .related-post .post-list .item .post_title {\r\n      font-size: 1rem;\r\n      color: #212529;\r\n      margin: 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n      text-decoration: none;\r\n          }\r\n\r\n    .related-post .post-list .item .post_excerpt {\r\n      font-size: 13px;\r\n      color: #3f3f3f;\r\n      margin: 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n      text-decoration: none;\r\n          }\r\n\r\n    .related-post .owl-dots .owl-dot {\r\n          }\r\n\r\n      <\/style>\r\n      <script>\r\n      jQuery(document).ready(function($) {\r\n        $(\".related-post .post-list\").owlCarousel({\r\n          items: 3,\r\n          responsiveClass: true,\r\n          responsive: {\r\n            0: {\r\n              items: 1,\r\n            },\r\n            768: {\r\n              items: 2,\r\n            },\r\n            1200: {\r\n              items: 3,\r\n            }\r\n          },\r\n                      rewind: true,\r\n                                loop: true,\r\n                                center: true,\r\n                                autoplay: true,\r\n            autoplayHoverPause: true,\r\n                                nav: true,\r\n            navSpeed: 1000,\r\n            navText: ['<i class=\"fas fa-chevron-left\"><\/i>', '<i class=\"fas fa-chevron-right\"><\/i>'],\r\n                                dots: true,\r\n            dotsSpeed: 1200,\r\n                                                    rtl: false,\r\n          \r\n        });\r\n      });\r\n    <\/script>\r\n  <\/div>\r\n","protected":false},"author":3,"featured_media":16567,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","footnotes":""},"categories":[7],"tags":[849,850,848],"class_list":["post-16537","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dot-net-development","tag-net-core-unit-test","tag-unit-testing","tag-unit-tests-in-net-core"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v24.6 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Setting Up and Writing Unit Tests in .NET Core - Positiwise<\/title>\n<meta name=\"description\" content=\"Learn how to set up effective unit tests in .NET Core. Enhance your .NET applications by mastering these techniques for robust unit testing.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/positiwise.com\/blog\/unit-tests-in-net-core\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Setting Up and Writing Unit Tests in .NET Core\" \/>\n<meta property=\"og:description\" content=\"Learn how to set up effective unit tests in .NET Core. Enhance your .NET applications by mastering these techniques for robust unit testing.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/positiwise.com\/blog\/unit-tests-in-net-core\" \/>\n<meta property=\"og:site_name\" content=\"Positiwise\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/positiwise\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-05-30T06:50:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-30T09:06:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Setting-up-and-writing-unit-tests-in-NET-Core-jpg.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1021\" \/>\n\t<meta property=\"og:image:height\" content=\"621\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Parag Mehta\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@positiwise\" \/>\n<meta name=\"twitter:site\" content=\"@positiwise\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Parag Mehta\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/unit-tests-in-net-core#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/unit-tests-in-net-core\"},\"author\":{\"name\":\"Parag Mehta\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#\\\/schema\\\/person\\\/b4b3d9970ea94f5914a615f70345353a\"},\"headline\":\"Setting Up and Writing Unit Tests in .NET Core\",\"datePublished\":\"2024-05-30T06:50:30+00:00\",\"dateModified\":\"2024-05-30T09:06:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/unit-tests-in-net-core\"},\"wordCount\":1142,\"publisher\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/unit-tests-in-net-core#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/Setting-up-and-writing-unit-tests-in-NET-Core-jpg.webp\",\"keywords\":[\".net core unit test\",\"unit testing\",\"unit tests in .net core\"],\"articleSection\":[\".NET Development\"],\"inLanguage\":\"en-US\",\"copyrightYear\":\"2022\",\"copyrightHolder\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/unit-tests-in-net-core\",\"url\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/unit-tests-in-net-core\",\"name\":\"Setting Up and Writing Unit Tests in .NET Core - Positiwise\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/unit-tests-in-net-core#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/unit-tests-in-net-core#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/Setting-up-and-writing-unit-tests-in-NET-Core-jpg.webp\",\"datePublished\":\"2024-05-30T06:50:30+00:00\",\"dateModified\":\"2024-05-30T09:06:54+00:00\",\"description\":\"Learn how to set up effective unit tests in .NET Core. Enhance your .NET applications by mastering these techniques for robust unit testing.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/unit-tests-in-net-core#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/positiwise.com\\\/blog\\\/unit-tests-in-net-core\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/unit-tests-in-net-core#primaryimage\",\"url\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/Setting-up-and-writing-unit-tests-in-NET-Core-jpg.webp\",\"contentUrl\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/Setting-up-and-writing-unit-tests-in-NET-Core-jpg.webp\",\"width\":1021,\"height\":621,\"caption\":\"Setting-up-and-writing-unit-tests-in-NET-Core\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/unit-tests-in-net-core#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/positiwise.com\\\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Setting Up and Writing Unit Tests in .NET Core\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/\",\"name\":\"Positiwise\",\"description\":\"Providing Full-cycle Software Development Services\",\"publisher\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#organization\"},\"alternateName\":\"Positiwise Software Pvt Ltd\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#organization\",\"name\":\"Positiwise\",\"alternateName\":\"Positiwise Software Pvt Ltd\",\"url\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/logo.png\",\"contentUrl\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/logo.png\",\"width\":202,\"height\":29,\"caption\":\"Positiwise\"},\"image\":{\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/positiwise\\\/\",\"https:\\\/\\\/x.com\\\/positiwise\",\"https:\\\/\\\/github.com\\\/positiwise\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/positiwise\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/#\\\/schema\\\/person\\\/b4b3d9970ea94f5914a615f70345353a\",\"name\":\"Parag Mehta\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/072ea4a638415a77610a840228d51b8225ad88856ed34d69cbe1fcd638390535?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/072ea4a638415a77610a840228d51b8225ad88856ed34d69cbe1fcd638390535?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/072ea4a638415a77610a840228d51b8225ad88856ed34d69cbe1fcd638390535?s=96&r=g\",\"caption\":\"Parag Mehta\"},\"description\":\"Parag Mehta, the CEO and Founder of Positiwise Software Pvt Ltd has extensive knowledge of the development niche. He is implementing custom strategies to craft highly-appealing and robust applications for its clients and supporting employees to grow and ace the tasks. He is a consistent learner and always provides the best-in-quality solutions, accelerating productivity.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/paragcmehta\"],\"url\":\"https:\\\/\\\/positiwise.com\\\/blog\\\/author\\\/parag-mehta\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Setting Up and Writing Unit Tests in .NET Core - Positiwise","description":"Learn how to set up effective unit tests in .NET Core. Enhance your .NET applications by mastering these techniques for robust unit testing.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/positiwise.com\/blog\/unit-tests-in-net-core","og_locale":"en_US","og_type":"article","og_title":"Setting Up and Writing Unit Tests in .NET Core","og_description":"Learn how to set up effective unit tests in .NET Core. Enhance your .NET applications by mastering these techniques for robust unit testing.","og_url":"https:\/\/positiwise.com\/blog\/unit-tests-in-net-core","og_site_name":"Positiwise","article_publisher":"https:\/\/www.facebook.com\/positiwise\/","article_published_time":"2024-05-30T06:50:30+00:00","article_modified_time":"2024-05-30T09:06:54+00:00","og_image":[{"width":1021,"height":621,"url":"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Setting-up-and-writing-unit-tests-in-NET-Core-jpg.webp","type":"image\/jpeg"}],"author":"Parag Mehta","twitter_card":"summary_large_image","twitter_creator":"@positiwise","twitter_site":"@positiwise","twitter_misc":{"Written by":"Parag Mehta","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/positiwise.com\/blog\/unit-tests-in-net-core#article","isPartOf":{"@id":"https:\/\/positiwise.com\/blog\/unit-tests-in-net-core"},"author":{"name":"Parag Mehta","@id":"https:\/\/positiwise.com\/blog\/#\/schema\/person\/b4b3d9970ea94f5914a615f70345353a"},"headline":"Setting Up and Writing Unit Tests in .NET Core","datePublished":"2024-05-30T06:50:30+00:00","dateModified":"2024-05-30T09:06:54+00:00","mainEntityOfPage":{"@id":"https:\/\/positiwise.com\/blog\/unit-tests-in-net-core"},"wordCount":1142,"publisher":{"@id":"https:\/\/positiwise.com\/blog\/#organization"},"image":{"@id":"https:\/\/positiwise.com\/blog\/unit-tests-in-net-core#primaryimage"},"thumbnailUrl":"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Setting-up-and-writing-unit-tests-in-NET-Core-jpg.webp","keywords":[".net core unit test","unit testing","unit tests in .net core"],"articleSection":[".NET Development"],"inLanguage":"en-US","copyrightYear":"2022","copyrightHolder":{"@id":"https:\/\/positiwise.com\/blog\/#organization"}},{"@type":"WebPage","@id":"https:\/\/positiwise.com\/blog\/unit-tests-in-net-core","url":"https:\/\/positiwise.com\/blog\/unit-tests-in-net-core","name":"Setting Up and Writing Unit Tests in .NET Core - Positiwise","isPartOf":{"@id":"https:\/\/positiwise.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/positiwise.com\/blog\/unit-tests-in-net-core#primaryimage"},"image":{"@id":"https:\/\/positiwise.com\/blog\/unit-tests-in-net-core#primaryimage"},"thumbnailUrl":"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Setting-up-and-writing-unit-tests-in-NET-Core-jpg.webp","datePublished":"2024-05-30T06:50:30+00:00","dateModified":"2024-05-30T09:06:54+00:00","description":"Learn how to set up effective unit tests in .NET Core. Enhance your .NET applications by mastering these techniques for robust unit testing.","breadcrumb":{"@id":"https:\/\/positiwise.com\/blog\/unit-tests-in-net-core#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/positiwise.com\/blog\/unit-tests-in-net-core"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/positiwise.com\/blog\/unit-tests-in-net-core#primaryimage","url":"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Setting-up-and-writing-unit-tests-in-NET-Core-jpg.webp","contentUrl":"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2024\/05\/Setting-up-and-writing-unit-tests-in-NET-Core-jpg.webp","width":1021,"height":621,"caption":"Setting-up-and-writing-unit-tests-in-NET-Core"},{"@type":"BreadcrumbList","@id":"https:\/\/positiwise.com\/blog\/unit-tests-in-net-core#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/positiwise.com\/blog"},{"@type":"ListItem","position":2,"name":"Setting Up and Writing Unit Tests in .NET Core"}]},{"@type":"WebSite","@id":"https:\/\/positiwise.com\/blog\/#website","url":"https:\/\/positiwise.com\/blog\/","name":"Positiwise","description":"Providing Full-cycle Software Development Services","publisher":{"@id":"https:\/\/positiwise.com\/blog\/#organization"},"alternateName":"Positiwise Software Pvt Ltd","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/positiwise.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/positiwise.com\/blog\/#organization","name":"Positiwise","alternateName":"Positiwise Software Pvt Ltd","url":"https:\/\/positiwise.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/positiwise.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/07\/logo.png","contentUrl":"https:\/\/positiwise.com\/blog\/wp-content\/uploads\/2023\/07\/logo.png","width":202,"height":29,"caption":"Positiwise"},"image":{"@id":"https:\/\/positiwise.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/positiwise\/","https:\/\/x.com\/positiwise","https:\/\/github.com\/positiwise","https:\/\/www.linkedin.com\/company\/positiwise"]},{"@type":"Person","@id":"https:\/\/positiwise.com\/blog\/#\/schema\/person\/b4b3d9970ea94f5914a615f70345353a","name":"Parag Mehta","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/072ea4a638415a77610a840228d51b8225ad88856ed34d69cbe1fcd638390535?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/072ea4a638415a77610a840228d51b8225ad88856ed34d69cbe1fcd638390535?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/072ea4a638415a77610a840228d51b8225ad88856ed34d69cbe1fcd638390535?s=96&r=g","caption":"Parag Mehta"},"description":"Parag Mehta, the CEO and Founder of Positiwise Software Pvt Ltd has extensive knowledge of the development niche. He is implementing custom strategies to craft highly-appealing and robust applications for its clients and supporting employees to grow and ace the tasks. He is a consistent learner and always provides the best-in-quality solutions, accelerating productivity.","sameAs":["https:\/\/www.linkedin.com\/in\/paragcmehta"],"url":"https:\/\/positiwise.com\/blog\/author\/parag-mehta"}]}},"_links":{"self":[{"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/posts\/16537","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/comments?post=16537"}],"version-history":[{"count":11,"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/posts\/16537\/revisions"}],"predecessor-version":[{"id":16565,"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/posts\/16537\/revisions\/16565"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/media\/16567"}],"wp:attachment":[{"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/media?parent=16537"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/categories?post=16537"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/positiwise.com\/blog\/wp-json\/wp\/v2\/tags?post=16537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}