I’ve got a C# abstract class which has behavior in a virtual method. I need to unit test that behavior in that virtual method (not in question: when that method gets called). I see three options:
1) create a dummy implementation of the abstract class
2) use the children to call the virtual method (duplicated tests per child implementation)
3) another option someone here points out
I’m leaning toward #1. Is that the smartest way to test this behavior?
Ideally you want to test just that class, so create a dummy implementation. If you’re using a mocking framework which supports mocking classes, that’s probably the easiest way of doing it. If your virtual method calls abstract (or virtual) methods defined in the abstract class, the mocking framework will allow you to validate that those calls occur. (On the other hand, you may wish to use the mocking framework to create a stub, if you’re more interested in the results than in testing the exact protocol involved between the abstract class and its children.)