chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Do you have any advice on how to test abstract base classes?

Can you create mock instances which can be used to test some of the base class functionality?

I'm currently trialling Typemock
asked by solidstore (3.2k points)

1 Answer

0 votes
Hi solidstore,

You can indeed use Isolator to enable unit testing abstract base classes. You may want to either unit test the base class itself, or isolate dependencies in those types. Isolator can create instances of abstract classes (and interfaces, for that matter) to achieve both goals.

For instance, if you want to create an instance of an abstract class, and have it run the original implementation of that class, you can do the following:
var fakeAbstract = Isolate.Fake.Instance<AbstactBaseClass>(Members.CallOriginal);


You can also stub out or set other expectations on abstract members:
Isolate.WhenCalled(() => fakeAbstract.AbstractMethod()).IgnoreCall();


I hope this helps; if you need further assistance (in this or any other matter in your trial) let me know.

Doron
Typemock Support
answered by doron (17.2k points)
...