Geeks With Blogs
Abhishek Anand Bits & Bytes about .net technology framework.

Unit Testing Protected Methods

You are responsible for unit testing your Protected methods just like the Public ones. The suggested guidance for how to do so is to create a fake class in your unit test that inherits from the class you are testing. Then in this new class, create public methods that expose the protected members of the base class. You can now use this fake child class in your tests.

Unit Testing Abstract Classes

You can unit test an Abstract Class’s implemented methods directly by using Moq. Moq provides a property “CallBase” that when set to true, uses the base classes implementation of the method in the mocked object. You can simply create a mocked object for the Abstract Class, set “CallBase” to true, and use test the base classes methods directly on it.

Posted on Monday, October 21, 2013 1:47 PM .net , unit testing , protected methods , abstract class | Back to top


Comments on this post: Unit Testing Abstract Class and Protected Methods

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Abhishek Anand | Powered by: GeeksWithBlogs.net