У нас вы можете посмотреть бесплатно How to Run the Same Unit Tests Against Multiple Implementations of an Interface in C# или скачать в максимальном доступном качестве, видео которое было загружено на ютуб. Для загрузки выберите вариант из формы ниже:
Если кнопки скачивания не
загрузились
НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если возникают проблемы со скачиванием видео, пожалуйста напишите в поддержку по адресу внизу
страницы.
Спасибо за использование сервиса ClipSaver.ru
Discover how to efficiently run unit tests on various implementations of a repository interface in C#. Eliminate duplication and streamline your testing process! --- This video is based on the question https://stackoverflow.com/q/81317/ asked by the user 'Anthony' ( https://stackoverflow.com/u/5599/ ) and on the answer https://stackoverflow.com/a/81475/ provided by the user 'belugabob' ( https://stackoverflow.com/u/13397/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions. Visit these links for original content and any more details, such as alternate solutions, comments, revision history etc. For example, the original title of the Question was: Using the same test suite on various implementations of a repository interface Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l... The original Question post is licensed under the 'CC BY-SA 2.5' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 2.5' ( https://creativecommons.org/licenses/... ) license. If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com. --- How to Run the Same Unit Tests Against Multiple Implementations of an Interface in C# In the world of software development, maintaining clean and efficient code is crucial, especially when it comes to testing. As you develop a web application in C#, such as one inspired by Rob Connery's ASP.NET MVC storefront, you might encounter a situation where you have multiple implementations of a repository interface and want to test them all without duplicating your efforts. This guide will guide you through a structured approach to run the same test suite against different implementations of a repository interface, specifically for a hypothetical IFooRepository. The Problem You have a repository interface, IFooRepository, with methods like: [[See Video to Reveal this Text or Code Snippet]] And you have three concrete implementations: ISqlFooRepository IFileFooRepository IMockFooRepository Next, you want to run the same unit test, such as verifying that the GetFoo method does not return a null result, for all three implementations. Currently, you have duplicated your test classes with variations only in a helper method used to retrieve the appropriate repository instance. This situation is not only tedious but also violates the DRY (Don't Repeat Yourself) principle. The Solution To efficiently address this issue, you can utilize an abstract class to consolidate your tests. Here’s a step-by-step breakdown of how to implement this: 1. Create an Abstract Test Class Start by defining an abstract class that includes concrete implementations of your test methods and a method to obtain the IFooRepository. For instance: [[See Video to Reveal this Text or Code Snippet]] 2. Derive Concrete Classes Next, create three derived classes, each implementing the GetRepository method to return a specific repository instance: [[See Video to Reveal this Text or Code Snippet]] 3. Adding to Your Test Suite Now that you have your abstract and derived classes, add all three test classes to your test suite. Each class will execute the same test from the abstract class but use its specific repository implementation. 4. Selective Test Running (Optional) In case you want to selectively run tests based on different categories (like 'quick' or 'slow'), you can utilize the MbUnit [FixtureCategory] attribute. Here's an example of how you might categorize your tests: [[See Video to Reveal this Text or Code Snippet]] Conclusion By creating an abstract test class and deriving specific implementations, you can easily run the same set of unit tests against different implementations of your repository interface without duplicating code. This method not only cleans up your testing code but also leverages the power of inheritance in C#. Feel free to adapt the proposed solution to your needs or explore other frameworks like MBUnit for similar functionalities. Happy coding!