I have started following Test Driven Development and find it very logical and helps me a lot.
I have one question
1) In lot of StackOverflow answers I have seen that people say abstract base class adds lot of friction to setup a test. If we use interfaces, there would be less friction.
What I am thinking is, if there is no default implementation in Abstract classes how does this make any difference in setting up the test.
For Eg : HttpContext … it exposes lot of properties which needs to be setup (read queryString,FormCollection etc). Here you have to mock all these things before you can actually use the HttpContext in a unit test. (I prefer using moq)
If someone can help me understand why this adds more friction, it would be helpful.
–RN
I can only think of one relevant difference with respect to unit testing (if we’re ruling out default implementations): an abstract classes’ methods may be sealed,* in which case they cannot be mocked, while interfaces never have this problem.
* Or final, or not declared virtual in the first place depending on the language.