Moq testing void method
问题 Hi I am new to Moq testing and having hard time to do a simple assertion. I am using an interface public interface IAdd { void add(int a, int b); } Moq for the IAdd interface is: Mock<IAdd> mockadd = new Mock<IAdd>(); mockadd.Setup(x => x.add(It.IsAny<int>(), It.IsAny<int>()).callback((int a, int b) => { a+b;}); IAdd testing = mockadd.Object; Since the add method is void, it doesn't return any value to Assert with. How can I assert this setup? 回答1: Why mocking is used? It used for verifying