interface itest { void run(); } class test : itest { void itest.run() => run(); public int run() { //... } }
hello, how verify itest.run() execute "run" of test?
you could test using mocking framework moq:
public interface itest { void run(); } public class test : itest { void itest.run() => run(); public virtual int run() { return 1; // doesn’t matter, replaced our mock } }
the test this:
// arrange mock<test> mock = new mock<test>(); mock.callbase = true; mock.setup(t => t.run()).returns(1); // act itest test = mock.object; test.run(); // assert mock.verify(t => t.run(), times.once());
this correctly throws when itest.run
not call run
of test
. however, can see, doing requires run
method virtual mock can overwrite own implementation. might not desireable.
and ultimately, test doesn’t not make sense. when unit test something, want unit test behavior, not implementation. shouldn’t matter whether explicit implementation itest.run
calls method on object or not. should care behavior of calling method correct.
Comments
Post a Comment