c# - Unit test to verify that a base class method is called -
i have base class:
public abstract class mybaseclass { protected virtual void method1() { } }
and derived class:
public class myderivedclass : mybaseclass { public void method2() { base.method1(); } }
i want write unit test method2
verify calls method1
on base class. i'm using moq mocking library. possible?
i came across related link:
mocking base class method call moq
in 2nd answer suggests can achieved setting callbase
property true on mock object. it's not clear how enable call base class method (method1
in above example) verified.
appreciate assistance this.
unit tests should verify behavior, not implementation. there several reasons this:
- the results goal, not how get results
- testing results allows improve implementation without re-writing tests
- implementations harder mock
you might able put in hooks or create mocks verify base method called, care how answer achieved, or care answer right?
if particular implementation require has side effects can verify, that should validating.
Comments
Post a Comment