Unit Testing: Logging and Dependency Injection

后端 未结 9 561
臣服心动
臣服心动 2021-02-02 14:57

So regards logging from SO and other sites on the Internet the best response seems to be:

void DoSomething() {
    Logger.Log(\"Doing something!\");
    // Code.         


        
9条回答
  •  [愿得一人]
    2021-02-02 15:41

    Personally I think its overkill to unit test logging statements. But if you really want to do it then a mock logger would work or, if using a framework like log4j, write a custom appender that is used during test runs.

提交回复
热议问题