Verifying sequence of private method calls in unit testing

前端 未结 2 927
暖寄归人
暖寄归人 2021-01-25 09:08

I have the following class:

class MyClass {

  public void doIt() {
     methodOne();
     methodTwo();
     methodThree();
  }

  private void methodOne() {
            


        
相关标签:
2条回答
  • 2021-01-25 09:18

    As long as your private methods are ... well ... private, don't test them. They are implementation details. They could be refactored without changing the contract of your class. Test the correct outcome of your public methods.

    0 讨论(0)
  • 2021-01-25 09:26

    Hate to be the person but: simply don't test this. Test the output, side effects, results - not the implementation.

    If you really want to ensure the correct order, extract these methods into separate class(es) and mock them.

    0 讨论(0)
提交回复
热议问题