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

后端 未结 4 2240
梦如初夏
梦如初夏 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:18

    The output can be suppressed by running the tests with go test .:

    $ go help test

    Go test runs in two different modes: local directory mode when invoked with no package arguments (for example, 'go test'), and package list mode when invoked with package arguments (for example 'go test math', 'go test ./...', and even 'go test .').

    In local directory mode, go test compiles and tests the package sources found in the current directory and then runs the resulting test binary. In this mode, caching (discussed below) is disabled. After the package test finishes, go test prints a summary line showing the test status ('ok' or 'FAIL'), package name, and elapsed time.

    In package list mode, go test compiles and tests each of the packages listed on the command line. If a package test passes, go test prints only the final 'ok' summary line. If a package test fails, go test prints the full test output. If invoked with the -bench or -v flag, go test prints the full output even for passing package tests, in order to display the requested benchmark results or verbose logging.

提交回复
热议问题