1. 程式人生 > >Golang單元測試、效能測試

Golang單元測試、效能測試

Test 單元測試
testing包提供了對Go包的自動測試支援。 這是和go test 命令相呼應的功能, go test 命令會自動執行所以符合格式
func TestXXX(t *testing.T)
的函式。

Benchmark 效能測試

Functions of the form
func BenchmarkXxx(b testing.B)
符合格式 (見上)的函式被認為是一個性能測試程式, 當帶著 -bench=“.” ( 引數必須有!)來執行**go test
命令的時候效能測試程式就會被順序執行。

   $ ls
    CONTRIBUTING.md  dependencies.go  goconvey     LICENSE.md  web
    convey           examples         goconvey.go  README.md
$ ./goconvey 
    2018/12/21 16:57:33 goconvey.go:63: Initial configuration: [host: 127.0.0.1] [port: 8080] [poll: 250ms] [cover: true]
    2018/12/21 16:57:33 tester.go:19: Now configured to test 10 packages concurrently.
    2018/12/21 16:57:33 goconvey.go:194: Serving HTTP at: http://127.0.0.1:8080
    2018/12/21 16:57:33 goconvey.go:107: Launching browser on 127.0.0.1:8080
    2018/12/21 16:57:33 integration.go:122: File system state modified, publishing current folders... 0 115903539471
    2018/12/21 16:57:33 goconvey.go:120: Received request from watcher to execute tests...
    2018/12/21 16:57:33 executor.go:69: Executor status: 'executing'
    2018/12/21 16:57:33 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey
    2018/12/21 16:57:33 coordinator.go:37: Skipping concurrent execution: github.com/smartystreets/goconvey/web/server/watch/integration_testing/sub
    2018/12/21 16:57:33 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/examples
    2018/12/21 16:57:33 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/client/resources/fonts/FontAwesome/css
    2018/12/21 16:57:33 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/client/resources/css/themes
    2018/12/21 16:57:33 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/client/resources/fonts/Open_Sans
    2018/12/21 16:57:33 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/server/system
    2018/12/21 16:57:33 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/client/resources/js
    2018/12/21 16:57:33 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/server/contract
    2018/12/21 16:57:33 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/server/messaging
    2018/12/21 16:57:33 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/client/reports
    2018/12/21 16:57:33 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/client/resources/fonts/Oswald
    2018/12/21 16:57:33 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/client/resources/js/lib
    2018/12/21 16:57:33 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/convey
    2018/12/21 16:57:33 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/convey/gotest
    2018/12/21 16:57:34 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/server/executor
    2018/12/21 16:57:34 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/server/watch/integration_testing
    2018/12/21 16:57:34 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/client/resources
    2018/12/21 16:57:35 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/client/resources/fonts/Orbitron
    2018/12/21 16:57:35 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web
    2018/12/21 16:57:35 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/client
    2018/12/21 16:57:35 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/server/parser
    2018/12/21 16:57:36 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/convey/reporting
    2018/12/21 16:57:36 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/client/resources/fonts/FontAwesome/fonts
    2018/12/21 16:57:36 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/client/resources/ico
    2018/12/21 16:57:36 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/server
    2018/12/21 16:57:36 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/server/api
    2018/12/21 16:57:36 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/server/watch
    2018/12/21 16:57:37 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/client/resources/css
    2018/12/21 16:57:37 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/client/resources/fonts
    2018/12/21 16:57:37 coordinator.go:46: Executing concurrent tests: github.com/smartystreets/goconvey/web/client/resources/fonts/FontAwesome
    2018/12/21 16:57:37 shell.go:102: Coverage output: ?    github.com/smartystreets/goconvey     [no test files]
    2018/12/21 16:57:37 shell.go:104: Run without coverage
    2018/12/21 16:57:37 goconvey.go:115: Created new window in existing browser session.
    
    2018/12/21 16:57:39 parser.go:24: [no test files]: github.com/smartystreets/goconvey
    2018/12/21 16:57:39 parser.go:24: [no go code]: github.com/smartystreets/goconvey/web/client/reports
    2018/12/21 16:57:39 parser.go:24: [no go code]: github.com/smartystreets/goconvey/web/client/resources/fonts/Open_Sans
    2018/12/21 16:57:39 parser.go:24: [passed]: github.com/smartystreets/goconvey/web/server/system
    2018/12/21 16:57:39 parser.go:24: [no go code]: github.com/smartystreets/goconvey/web/client/resources/css/themes
    2018/12/21 16:57:39 parser.go:24: [no go code]: github.com/smartystreets/goconvey/web/client/resources/fonts/FontAwesome/css
    2018/12/21 16:57:39 parser.go:24: [no go code]: github.com/smartystreets/goconvey/web/client/resources/js
    2018/12/21 16:57:39 parser.go:24: [no test functions]: github.com/smartystreets/goconvey/web/server/contract
    2018/12/21 16:57:39 parser.go:24: [no test functions]: github.com/smartystreets/goconvey/web/server/messaging
    2018/12/21 16:57:39 parser.go:24: [disabled]: github.com/smartystreets/goconvey/web/server/watch/integration_testing/sub
    2018/12/21 16:57:39 parser.go:24: [passed]: github.com/smartystreets/goconvey/examples
    2018/12/21 16:57:39 parser.go:24: [no go code]: github.com/smartystreets/goconvey/web/client/resources/fonts/Oswald
    2018/12/21 16:57:39 parser.go:24: [no go code]: github.com/smartystreets/goconvey/web/client/resources/js/lib
    2018/12/21 16:57:39 parser.go:24: [passed]: github.com/smartystreets/goconvey/convey
    2018/12/21 16:57:39 parser.go:24: [no test functions]: github.com/smartystreets/goconvey/convey/gotest
    2018/12/21 16:57:39 parser.go:24: [passed]: github.com/smartystreets/goconvey/web/server/executor
    2018/12/21 16:57:39 parser.go:24: [no test functions]: github.com/smartystreets/goconvey/web/server/watch/integration_testing
    2018/12/21 16:57:39 parser.go:24: [no go code]: github.com/smartystreets/goconvey/web/client/resources
    2018/12/21 16:57:39 parser.go:24: [no go code]: github.com/smartystreets/goconvey/web/client/resources/fonts/Orbitron
    2018/12/21 16:57:39 parser.go:24: [no go code]: github.com/smartystreets/goconvey/web
    2018/12/21 16:57:39 parser.go:24: [no go code]: github.com/smartystreets/goconvey/web/client
    2018/12/21 16:57:39 parser.go:24: [passed]: github.com/smartystreets/goconvey/web/server/parser
    2018/12/21 16:57:39 parser.go:24: [passed]: github.com/smartystreets/goconvey/convey/reporting
    2018/12/21 16:57:39 parser.go:24: [no go code]: github.com/smartystreets/goconvey/web/client/resources/fonts/FontAwesome/fonts
    2018/12/21 16:57:39 parser.go:24: [no go code]: github.com/smartystreets/goconvey/web/client/resources/ico
    2018/12/21 16:57:39 parser.go:24: [no go code]: github.com/smartystreets/goconvey/web/server
    2018/12/21 16:57:39 parser.go:24: [passed]: github.com/smartystreets/goconvey/web/server/api
    2018/12/21 16:57:39 parser.go:24: [passed]: github.com/smartystreets/goconvey/web/server/watch
    2018/12/21 16:57:39 parser.go:24: [no go code]: github.com/smartystreets/goconvey/web/client/resources/css
    2018/12/21 16:57:39 parser.go:24: [no go code]: github.com/smartystreets/goconvey/web/client/resources/fonts
    2018/12/21 16:57:39 parser.go:24: [no go code]: github.com/smartystreets/goconvey/web/client/resources/fonts/FontAwesome
    2018/12/21 16:57:39 executor.go:69: Executor status: 'idle'

在這裡插入圖片描述