How to assign values to properties in moq?

后端 未结 2 750
我在风中等你
我在风中等你 2020-12-04 21:18

I have a class with a method that returns an object of type User

public class CustomMembershipProvider : MembershipProvider
{
    public virtual         


        
2条回答
  •  Happy的楠姐
    2020-12-04 22:11

    I think you are missing purpose of mocking. Mocks used to mock dependencies of class you are testing:

    enter image description here

    System under test (SUT) should be tested in isolation (i.e. separate from other units). Otherwise errors in dependencies will cause your SUTs tests to fail. Also you should not write tests for mocks. That gives you nothing, because mocks are not production code. Mocks are not executed in your application.

    So, you should mock CustomMembershipProvider only if you are testing some unit, which depends on it (BTW it's better to create some abstraction like interface ICustomMembershipProvider to depend on).

    Or, if you are writing tests for CustomMembershipProvider class, then it should not be mocked - only dependencies of this provider should be mocked.

提交回复
热议问题