Using Moq to verify execution of private methods

后端 未结 2 915
谎友^
谎友^ 2021-01-18 09:24

I want to test the following logic (this is obviously a stripped-down version of my method):

public void myPublicMethod(params) {

    if(some_condition)
            


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-18 09:55

    Don't test private methods. They are private implementation details of the class. You should only test the results of executing public methods. As long as your results come out as expected, you shouldn't care how the result is obtained.

    Building tests on private methods will lead to brittle tests that break easily when you refactor private implementations (for performance or other reasons).

提交回复
热议问题