jjzjj

ConsolePrinter

全部标签

unit-testing - 如何测试在 golang 中打印到控制台的方法?

我有下一个结构。packageloggerimport"fmt"typeIPrinterinterface{Print(valuestring)}typeConsolePrinterstruct{}func(cp*ConsolePrinter)Print(valuestring){fmt.Printf("thisisvalue:%s",value)}测试范围说我需要测试ConsolePrinterPrint方法。如何覆盖这个方法?谢谢。 最佳答案 根据@icza写的评论,我在下面编写了测试。funcTestPrint(t*testi