{"id":7793,"date":"2023-06-27T15:21:10","date_gmt":"2023-06-27T13:21:10","guid":{"rendered":"https:\/\/medtech-ingenieur.de\/?p=7793"},"modified":"2023-08-02T14:38:52","modified_gmt":"2023-08-02T12:38:52","slug":"interfaces-fuer-unittests","status":"publish","type":"post","link":"https:\/\/medtech-ingenieur.de\/en\/interfaces-fuer-unittests\/","title":{"rendered":"Interfaces for better unit tests"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-7955\" src=\"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Software-Engineer-1-300x300.jpg\" alt=\"\" width=\"300\" height=\"300\" srcset=\"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Software-Engineer-1-300x300.jpg 300w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Software-Engineer-1-150x150.jpg 150w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Software-Engineer-1-768x768.jpg 768w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Software-Engineer-1-1024x1024.jpg 1024w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Software-Engineer-1-100x100.jpg 100w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Software-Engineer-1-200x200.jpg 200w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Software-Engineer-1-450x450.jpg 450w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Software-Engineer-1-600x600.jpg 600w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Software-Engineer-1-900x900.jpg 900w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Software-Engineer-1.jpg 1080w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>In this blog post, I&#039;d like to use a simple example to show you how you can use interfaces in C# to enable independent testing of individual classes in your C# projects. The example builds on my last post, &quot;<a href=\"https:\/\/medtech-ingenieur.de\/en\/unit-testen-c\/\">Getting started with unit testing in C# \u2013 Setup, basics and helpful tools<\/a>&quot; on.<\/p>\n<h2>Why should unit tests be run independently of the class?<\/h2>\n<p>The purpose of unit tests is to independently test individual sections of code for their functionality. However, classes or methods may depend on another class. In these cases, the code sections cannot be tested independently. This is particularly problematic if the class on which the section we are testing depends is not yet fully tested, contains errors, or perhaps hasn&#039;t even been implemented yet.<\/p>\n<p>The following example shows how the NuGet package \u201cFakeItEasy\u201d and interfaces can be used to test classes independently.<\/p>\n<p>&nbsp;<\/p>\n<h2>Example \u2013 The class to be tested depends on another class<\/h2>\n<p>In this example, which is based on the blog post: &quot;Getting Started with Unit Testing in C# \u2013 Setup, Basics, and Helpful Tools,&quot; we have our test class, Calculator (Figure 1). We want to test the method Calc(int n1, int n2, operation operation) for the case of addition. Calc(int n1, int n2, operation operation) calls a method of an instance of the Addition class (Figure 2), which is incorrectly implemented, causing our method Calc(int n1, int n2, operation operation) to return a false value.<\/p>\n<p>The unit test from Figure 3, which tests the method Calc(int n1, int n2, operation operation), also depends on the class Addition and not exclusively on our class Calculator.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7795\" src=\"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild1.png\" alt=\"\" width=\"422\" height=\"502\" srcset=\"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild1.png 422w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild1-252x300.png 252w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild1-100x119.png 100w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild1-150x178.png 150w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild1-200x238.png 200w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild1-300x357.png 300w\" sizes=\"auto, (max-width: 422px) 100vw, 422px\" \/><br \/>\n<em>Figure 1 The class Calculator to be tested has an object of the class Addition and uses this in the method Calc to calculate the result<\/em><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7796\" src=\"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild2.png\" alt=\"\" width=\"373\" height=\"275\" srcset=\"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild2.png 373w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild2-300x221.png 300w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild2-100x74.png 100w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild2-150x111.png 150w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild2-200x147.png 200w\" sizes=\"auto, (max-width: 373px) 100vw, 373px\" \/><br \/>\n<em>Figure 2 The Addition class, on which our Calculator class depends, is incorrectly implemented and returns the number 0 as the return value for each call to the Add(int n1, int n2) method<\/em><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7797\" src=\"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild3.png\" alt=\"\" width=\"605\" height=\"334\" srcset=\"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild3.png 605w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild3-300x166.png 300w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild3-100x55.png 100w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild3-150x83.png 150w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild3-200x110.png 200w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild3-450x248.png 450w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild3-600x331.png 600w\" sizes=\"auto, (max-width: 605px) 100vw, 605px\" \/><br \/>\n<em>Figure 3 The unit test for testing the method Calc(int n1, int n2, operation operation) fails because the class Addition returns the wrong result<\/em><\/p>\n<p>The test in Figure 3 will fail if we run it\u2014not because our method Calc(int n1, int n2, operation operation) is incorrectly implemented, but because the error lies in the Addition class. Our unit test cannot pass as long as the Addition class is not correctly implemented.<\/p>\n<p>&nbsp;<\/p>\n<h2>Example \u2013 Using an interface to enable independent testing<\/h2>\n<p>To be able to test our method Calc(int n1, int n2, operation operation) independently, we create an interface IAddition (Figure 4). This interface defines the interface between the Calculator and Addition.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7794\" src=\"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild4.png\" alt=\"\" width=\"340\" height=\"118\" srcset=\"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild4.png 340w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild4-300x104.png 300w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild4-100x35.png 100w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild4-150x52.png 150w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild4-200x69.png 200w\" sizes=\"auto, (max-width: 340px) 100vw, 340px\" \/><br \/>\n<em>Figure 4 Interface to define the interface to the class Addition<\/em><\/p>\n<p>As shown in Figure 5, the Addition class inherits from the IAddition interface. Therefore, the Addition class is required to implement a method Add(int n1, int n2) with a float return value.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7799\" src=\"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild5.png\" alt=\"\" width=\"278\" height=\"167\" srcset=\"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild5.png 278w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild5-100x60.png 100w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild5-150x90.png 150w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild5-200x120.png 200w\" sizes=\"auto, (max-width: 278px) 100vw, 278px\" \/><br \/>\n<em>Figure 5 Our class Addition now inherits from the interface IAddition<\/em><\/p>\n<p>In the Calculator class, we now change the type of the variable Addition to IAddition. We can still initialize it with an object of type Addition, since the Addition class inherits from the IAddition interface.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7800\" src=\"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild6.png\" alt=\"\" width=\"400\" height=\"113\" srcset=\"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild6.png 400w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild6-300x85.png 300w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild6-100x28.png 100w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild6-150x42.png 150w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild6-200x57.png 200w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><br \/>\n<em>Figure 6 Changing the type of the variable Addition in our calculator<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>What does this mean for our test? We can now &quot;mock&quot; our interface using the NuGet package FakeItEasy, meaning we can create an object that implements this interface. In Figure 7, in the Arrange block, line 27 creates a mock instance called fakeAddition that implements the IAddition interface. The variable Addition from our Calculator is then replaced with fakeAddition in line 28. Furthermore, in line 30, we specify that if our fakeAddition calls the Add method with the input parameters number1 and number2, the value (number1 + number2) should be returned.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7798\" src=\"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild7.png\" alt=\"\" width=\"605\" height=\"264\" srcset=\"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild7.png 605w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild7-300x131.png 300w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild7-100x44.png 100w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild7-150x65.png 150w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild7-200x87.png 200w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild7-450x196.png 450w, https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Bild7-600x262.png 600w\" sizes=\"auto, (max-width: 605px) 100vw, 605px\" \/><br \/>\n<em>Figure 7 Adaptation of the unit test to create a mock object of type IAddition and use it instead of the class Addition<\/em><\/p>\n<p>This unit test will now pass when executed, as it no longer accesses the Addition class, but instead accesses our mock object, fakeAddition. Our Calculator class can now be tested successfully and independently of the Addition class.<\/p>\n<p>&nbsp;<\/p>\n<h2>Examples \u2013 What else can be mocked with FakeItEasy<\/h2>\n<p>FakeItEasy offers many options for making tests more detailed and comprehensive. Using interfaces and FakeItEasy, we can create mock instances and specify how they should behave. Below are a few examples of what can be specified for mock instances.<\/p>\n<ul>\n<li>We can specify how often a method of an interface may be called in order for the test to pass<br \/>\nA.CallTo(() =&gt; fakeAddition.Add(A.Ignored, A.Ignored)).MustHaveHappened(1, Times.Exactly);<\/li>\n<li>We can set return parameters of a method for specific input parameters<br \/>\nA.CallTo(() =&gt; fakeAddition.Add(number1, number2)).Returns(number1 + number2<\/li>\n<li>We can set return parameters of a method for any input parameters<br \/>\nA.CallTo(() =&gt; fakeAddition.Add(A.Ignored, A.Ignored)).Returns(3);<\/li>\n<li>We can specify a sequence of return parameters for a method, which should be returned one after the other regardless of what the input parameters are<br \/>\nA.CallTo(() =&gt; fakeAddition.Add(A.Ignored, A.Ignored)).ReturnsNextFromSequence(new float[] { 0.1f, 0.4f, 0.0f });<\/li>\n<li>We can specify exceptions that should be thrown when a method of our mock instance is called<br \/>\nA.CallTo(() =&gt; fakeAddition.Add(A.Ignored, A.Ignored)).Throws();<\/li>\n<\/ul>\n<p>Further ways to use FakeItEasy and examples can be found at: https:\/\/fakeiteasy.github.io\/docs\/7.3.1\/<\/p>\n<h2>Conclusion<\/h2>\n<p>We can use interfaces specifically to define interfaces between classes. These interfaces ensure the independent testability of these classes. Using FakeItEasy, interfaces can be used to control the flow of information through the interface during unit tests. This allows us to, for example, specify return parameters for specific function calls, control how often the functions of an interface can be called, and much more.<\/p>","protected":false},"excerpt":{"rendered":"<p>In diesem Blogeintrag m\u00f6chte ich dir anhand eines einfachen Beispiels zeigen, wie Du Interfaces in C# gezielt einsetzten kannst, um das unabh\u00e4ngige Testen einzelner Klassen in deinen C#-Projekten zu erm\u00f6glichen. Das hierf\u00fcr verwendete Beispiel baut auf meinem letzten Beitrag \u201eEinstieg ins Unit-Testen in C# \u2013 Setup, Basics und Hilfreiche Tools\u201c auf. Warum sollten Unittests unabh\u00e4ngig [&hellip;]<\/p>\n","protected":false},"author":40,"featured_media":7955,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,6,7,468],"tags":[649,665,232,357,664],"class_list":["post-7793","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-allgemein","category-software","category-systemarchitekten","category-testen","tag-c","tag-interface","tag-test","tag-unit","tag-unittest","post-wrapper","thrv_wrapper"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Interfaces f\u00fcr bessere Unittests - MEDtech Ingenieur GmbH<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/medtech-ingenieur.de\/en\/interfaces-fuer-unittests\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Interfaces f\u00fcr bessere Unittests - MEDtech Ingenieur GmbH\" \/>\n<meta property=\"og:description\" content=\"In diesem Blogeintrag m\u00f6chte ich dir anhand eines einfachen Beispiels zeigen, wie Du Interfaces in C# gezielt einsetzten kannst, um das unabh\u00e4ngige Testen einzelner Klassen in deinen C#-Projekten zu erm\u00f6glichen. Das hierf\u00fcr verwendete Beispiel baut auf meinem letzten Beitrag \u201eEinstieg ins Unit-Testen in C# \u2013 Setup, Basics und Hilfreiche Tools\u201c auf. Warum sollten Unittests unabh\u00e4ngig [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/medtech-ingenieur.de\/en\/interfaces-fuer-unittests\/\" \/>\n<meta property=\"og:site_name\" content=\"MEDtech Ingenieur GmbH\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/medtechIngenieur\" \/>\n<meta property=\"article:published_time\" content=\"2023-06-27T13:21:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-02T12:38:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Software-Engineer-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1080\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Alisa Schulz\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@MedtechIng\" \/>\n<meta name=\"twitter:site\" content=\"@MedtechIng\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Alisa Schulz\" \/>\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:\\\/\\\/medtech-ingenieur.de\\\/interfaces-fuer-unittests\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/medtech-ingenieur.de\\\/interfaces-fuer-unittests\\\/\"},\"author\":{\"name\":\"Alisa Schulz\",\"@id\":\"https:\\\/\\\/medtech-ingenieur.de\\\/#\\\/schema\\\/person\\\/3c1800422d500e3f54ac7baa2c493948\"},\"headline\":\"Interfaces f\u00fcr bessere Unittests\",\"datePublished\":\"2023-06-27T13:21:10+00:00\",\"dateModified\":\"2023-08-02T12:38:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/medtech-ingenieur.de\\\/interfaces-fuer-unittests\\\/\"},\"wordCount\":1003,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/medtech-ingenieur.de\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/medtech-ingenieur.de\\\/interfaces-fuer-unittests\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/medtech-ingenieur.de\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/Software-Engineer-1.jpg\",\"keywords\":[\"c#\",\"interface\",\"Test\",\"unit\",\"unittest\"],\"articleSection\":[\"Allgemein\",\"Software\",\"Systems Engineering\",\"Testen\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/medtech-ingenieur.de\\\/interfaces-fuer-unittests\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/medtech-ingenieur.de\\\/interfaces-fuer-unittests\\\/\",\"url\":\"https:\\\/\\\/medtech-ingenieur.de\\\/interfaces-fuer-unittests\\\/\",\"name\":\"Interfaces f\u00fcr bessere Unittests - MEDtech Ingenieur GmbH\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/medtech-ingenieur.de\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/medtech-ingenieur.de\\\/interfaces-fuer-unittests\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/medtech-ingenieur.de\\\/interfaces-fuer-unittests\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/medtech-ingenieur.de\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/Software-Engineer-1.jpg\",\"datePublished\":\"2023-06-27T13:21:10+00:00\",\"dateModified\":\"2023-08-02T12:38:52+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/medtech-ingenieur.de\\\/interfaces-fuer-unittests\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/medtech-ingenieur.de\\\/interfaces-fuer-unittests\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/medtech-ingenieur.de\\\/interfaces-fuer-unittests\\\/#primaryimage\",\"url\":\"https:\\\/\\\/medtech-ingenieur.de\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/Software-Engineer-1.jpg\",\"contentUrl\":\"https:\\\/\\\/medtech-ingenieur.de\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/Software-Engineer-1.jpg\",\"width\":1080,\"height\":1080},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/medtech-ingenieur.de\\\/interfaces-fuer-unittests\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Startseite\",\"item\":\"https:\\\/\\\/medtech-ingenieur.de\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Interfaces f\u00fcr bessere Unittests\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/medtech-ingenieur.de\\\/#website\",\"url\":\"https:\\\/\\\/medtech-ingenieur.de\\\/\",\"name\":\"MEDtech Ingenieur GmbH\",\"description\":\"Ingenieursdienstleister f\u00fcr Medizintechnik\",\"publisher\":{\"@id\":\"https:\\\/\\\/medtech-ingenieur.de\\\/#organization\"},\"alternateName\":\"MEDtech\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/medtech-ingenieur.de\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/medtech-ingenieur.de\\\/#organization\",\"name\":\"MEDtech Ingenieur\",\"alternateName\":\"MEDtech\",\"url\":\"https:\\\/\\\/medtech-ingenieur.de\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/medtech-ingenieur.de\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/medtech-ingenieur.de\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/logo-700x700-1.png\",\"contentUrl\":\"https:\\\/\\\/medtech-ingenieur.de\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/logo-700x700-1.png\",\"width\":700,\"height\":700,\"caption\":\"MEDtech Ingenieur\"},\"image\":{\"@id\":\"https:\\\/\\\/medtech-ingenieur.de\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/medtechIngenieur\",\"https:\\\/\\\/x.com\\\/MedtechIng\",\"https:\\\/\\\/www.instagram.com\\\/medtech.ingenieure\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/37871229\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/medtech-ingenieur.de\\\/#\\\/schema\\\/person\\\/3c1800422d500e3f54ac7baa2c493948\",\"name\":\"Alisa Schulz\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/12cc2ec96702ad3d6669a851c07c9d09d71c8318e25533a7a1491b7f510ec69b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/12cc2ec96702ad3d6669a851c07c9d09d71c8318e25533a7a1491b7f510ec69b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/12cc2ec96702ad3d6669a851c07c9d09d71c8318e25533a7a1491b7f510ec69b?s=96&d=mm&r=g\",\"caption\":\"Alisa Schulz\"},\"url\":\"https:\\\/\\\/medtech-ingenieur.de\\\/en\\\/author\\\/alisa\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Interfaces for improved unit tests - MEDtech Ingenieur GmbH","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:\/\/medtech-ingenieur.de\/en\/interfaces-fuer-unittests\/","og_locale":"en_US","og_type":"article","og_title":"Interfaces f\u00fcr bessere Unittests - MEDtech Ingenieur GmbH","og_description":"In diesem Blogeintrag m\u00f6chte ich dir anhand eines einfachen Beispiels zeigen, wie Du Interfaces in C# gezielt einsetzten kannst, um das unabh\u00e4ngige Testen einzelner Klassen in deinen C#-Projekten zu erm\u00f6glichen. Das hierf\u00fcr verwendete Beispiel baut auf meinem letzten Beitrag \u201eEinstieg ins Unit-Testen in C# \u2013 Setup, Basics und Hilfreiche Tools\u201c auf. Warum sollten Unittests unabh\u00e4ngig [&hellip;]","og_url":"https:\/\/medtech-ingenieur.de\/en\/interfaces-fuer-unittests\/","og_site_name":"MEDtech Ingenieur GmbH","article_publisher":"https:\/\/www.facebook.com\/medtechIngenieur","article_published_time":"2023-06-27T13:21:10+00:00","article_modified_time":"2023-08-02T12:38:52+00:00","og_image":[{"width":1080,"height":1080,"url":"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Software-Engineer-1.jpg","type":"image\/jpeg"}],"author":"Alisa Schulz","twitter_card":"summary_large_image","twitter_creator":"@MedtechIng","twitter_site":"@MedtechIng","twitter_misc":{"Written by":"Alisa Schulz","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/medtech-ingenieur.de\/interfaces-fuer-unittests\/#article","isPartOf":{"@id":"https:\/\/medtech-ingenieur.de\/interfaces-fuer-unittests\/"},"author":{"name":"Alisa Schulz","@id":"https:\/\/medtech-ingenieur.de\/#\/schema\/person\/3c1800422d500e3f54ac7baa2c493948"},"headline":"Interfaces f\u00fcr bessere Unittests","datePublished":"2023-06-27T13:21:10+00:00","dateModified":"2023-08-02T12:38:52+00:00","mainEntityOfPage":{"@id":"https:\/\/medtech-ingenieur.de\/interfaces-fuer-unittests\/"},"wordCount":1003,"commentCount":0,"publisher":{"@id":"https:\/\/medtech-ingenieur.de\/#organization"},"image":{"@id":"https:\/\/medtech-ingenieur.de\/interfaces-fuer-unittests\/#primaryimage"},"thumbnailUrl":"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Software-Engineer-1.jpg","keywords":["c#","interface","Test","unit","unittest"],"articleSection":["Allgemein","Software","Systems Engineering","Testen"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/medtech-ingenieur.de\/interfaces-fuer-unittests\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/medtech-ingenieur.de\/interfaces-fuer-unittests\/","url":"https:\/\/medtech-ingenieur.de\/interfaces-fuer-unittests\/","name":"Interfaces for improved unit tests - MEDtech Ingenieur GmbH","isPartOf":{"@id":"https:\/\/medtech-ingenieur.de\/#website"},"primaryImageOfPage":{"@id":"https:\/\/medtech-ingenieur.de\/interfaces-fuer-unittests\/#primaryimage"},"image":{"@id":"https:\/\/medtech-ingenieur.de\/interfaces-fuer-unittests\/#primaryimage"},"thumbnailUrl":"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Software-Engineer-1.jpg","datePublished":"2023-06-27T13:21:10+00:00","dateModified":"2023-08-02T12:38:52+00:00","breadcrumb":{"@id":"https:\/\/medtech-ingenieur.de\/interfaces-fuer-unittests\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/medtech-ingenieur.de\/interfaces-fuer-unittests\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/medtech-ingenieur.de\/interfaces-fuer-unittests\/#primaryimage","url":"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Software-Engineer-1.jpg","contentUrl":"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2023\/06\/Software-Engineer-1.jpg","width":1080,"height":1080},{"@type":"BreadcrumbList","@id":"https:\/\/medtech-ingenieur.de\/interfaces-fuer-unittests\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Startseite","item":"https:\/\/medtech-ingenieur.de\/"},{"@type":"ListItem","position":2,"name":"Interfaces f\u00fcr bessere Unittests"}]},{"@type":"WebSite","@id":"https:\/\/medtech-ingenieur.de\/#website","url":"https:\/\/medtech-ingenieur.de\/","name":"MEDtech Ingenieur GmbH","description":"Engineering service provider for medical technology","publisher":{"@id":"https:\/\/medtech-ingenieur.de\/#organization"},"alternateName":"MEDtech","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/medtech-ingenieur.de\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/medtech-ingenieur.de\/#organization","name":"MEDtech Engineer","alternateName":"MEDtech","url":"https:\/\/medtech-ingenieur.de\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/medtech-ingenieur.de\/#\/schema\/logo\/image\/","url":"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2024\/01\/logo-700x700-1.png","contentUrl":"https:\/\/medtech-ingenieur.de\/wp-content\/uploads\/2024\/01\/logo-700x700-1.png","width":700,"height":700,"caption":"MEDtech Ingenieur"},"image":{"@id":"https:\/\/medtech-ingenieur.de\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/medtechIngenieur","https:\/\/x.com\/MedtechIng","https:\/\/www.instagram.com\/medtech.ingenieure\/","https:\/\/www.linkedin.com\/company\/37871229\/"]},{"@type":"Person","@id":"https:\/\/medtech-ingenieur.de\/#\/schema\/person\/3c1800422d500e3f54ac7baa2c493948","name":"Alisa Schulz","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/12cc2ec96702ad3d6669a851c07c9d09d71c8318e25533a7a1491b7f510ec69b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/12cc2ec96702ad3d6669a851c07c9d09d71c8318e25533a7a1491b7f510ec69b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/12cc2ec96702ad3d6669a851c07c9d09d71c8318e25533a7a1491b7f510ec69b?s=96&d=mm&r=g","caption":"Alisa Schulz"},"url":"https:\/\/medtech-ingenieur.de\/en\/author\/alisa\/"}]}},"_links":{"self":[{"href":"https:\/\/medtech-ingenieur.de\/en\/wp-json\/wp\/v2\/posts\/7793","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/medtech-ingenieur.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/medtech-ingenieur.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/medtech-ingenieur.de\/en\/wp-json\/wp\/v2\/users\/40"}],"replies":[{"embeddable":true,"href":"https:\/\/medtech-ingenieur.de\/en\/wp-json\/wp\/v2\/comments?post=7793"}],"version-history":[{"count":12,"href":"https:\/\/medtech-ingenieur.de\/en\/wp-json\/wp\/v2\/posts\/7793\/revisions"}],"predecessor-version":[{"id":7956,"href":"https:\/\/medtech-ingenieur.de\/en\/wp-json\/wp\/v2\/posts\/7793\/revisions\/7956"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/medtech-ingenieur.de\/en\/wp-json\/wp\/v2\/media\/7955"}],"wp:attachment":[{"href":"https:\/\/medtech-ingenieur.de\/en\/wp-json\/wp\/v2\/media?parent=7793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/medtech-ingenieur.de\/en\/wp-json\/wp\/v2\/categories?post=7793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/medtech-ingenieur.de\/en\/wp-json\/wp\/v2\/tags?post=7793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}