How to test Go function containing log.Fatal()

后端 未结 8 2259
南笙
南笙 2020-12-09 08:10

Say, I had the following code that prints some log messages. How would I go about testing that the correct messages have been logged? As log.Fatal calls o

8条回答
  •  感动是毒
    2020-12-09 09:02

    You cannot and you should not. This "you must 'test' each and every line"-attitude is strange, especially for terminal conditions and that's what log.Fatal is for. (Or just test it from the outside.)

提交回复
热议问题