unit testing and Static methods

前端 未结 3 486
清歌不尽
清歌不尽 2020-11-28 21:45

Reading up and picking up on unit testing, trying to make sense of the following post on that explains the hardships of static function calls.

I don\'t clearly unde

3条回答
  •  广开言路
    2020-11-28 22:22

    I do not see any problem when testing static methods (at least none that doesn't exists in non-static methods).

    • Mock objects are passed to classes under test using dependency injection.
    • Mock static methods can be passed to classes under test using a suitable autoloader or manipulating the include_path.
    • Late static binding deals with methods calling static methods in the same class.

提交回复
热议问题