I have the following code:
class MyBase
{
public virtual void foo()
{ ... }
}
class MyDerived : MyBase
{
public override void foo()
{
...
base.foo();
...
}
}
How can I test the method foo in MyDerived Class without executing the base.foo() method ?
You can’t, basically. Test the base class method separately so that you have confidence in that, and then you can test the derived class relying on the base class behaviour.
(This is another case where composition gives more control than inheritance – if your derived class composed the base class instead, you could use a mock or whatever instead. Not that it’s always appropriate of course, but…)