How can stdout be captured or suppressed for Go(lang) testing?

后端 未结 4 2247
梦如初夏
梦如初夏 2021-02-20 04:32

How can stdout be captured or suppressed for Go testing?

I am trying to teach myself go(lang) testing. In the code below, myshow.LoadPath prints lots of information to

4条回答
  •  無奈伤痛
    2021-02-20 05:30

    os.Stdout which is used by the fmt.Printf and others is just a variable. So you can overwrite it at any time and restore it back when necessary. https://golang.org/pkg/os/#pkg-variables

提交回复
热议问题