本文主要是介绍Golang test编译使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
创建文件my_test.go
package testsimport "testing"func TestMy(t *testing.T) {t.Log("TestMy")
}
通常用法:
$ go test -v -run TestMy my_test.go
=== RUN TestMyTestMy: my_test.go:6: TestMy
--- PASS: TestMy (0.00s)
PASS
ok command-line-arguments 0.619s
编译测试文件
go test -c my_test.go -o my.test
如果不用-o
则会生成tests.test
文件
编译后使用
$ ./my.test -test.v -test.run TestMy
=== RUN TestMyTestMy: my_test.go:6: TestMy
--- PASS: TestMy (0.00s)
PASS
测试命令参数:
-test.bench regexprun only benchmarks matching regexp
-test.benchmemprint memory allocations for benchmarks
-test.benchtime drun each benchmark for duration d (default 1s)
-test.blockprofile filewrite a goroutine blocking profile to file
-test.blockprofilerate rateset blocking profile rate (see runtime.SetBlockProfileRate) (default 1)
-test.count nrun tests and benchmarks n times (default 1)
-test.coverprofile filewrite a coverage profile to file
-test.cpu listcomma-separated list of cpu counts to run each test with
-test.cpuprofile filewrite a cpu profile to file
-test.failfastdo not start new tests after the first test failure
-test.list regexplist tests, examples, and benchmarks matching regexp then exit
-test.memprofile filewrite an allocation profile to file
-test.memprofilerate rateset memory allocation profiling rate (see runtime.MemProfileRate)
-test.mutexprofile stringwrite a mutex contention profile to the named file after execution
-test.mutexprofilefraction intif >= 0, calls runtime.SetMutexProfileFraction() (default 1)
-test.outputdir dirwrite profiles to dir
-test.parallel nrun at most n tests in parallel (default 12)
-test.run regexprun only tests and examples matching regexp
-test.shortrun smaller test suite to save time
-test.testlogfile filewrite test action log to file (for use only by cmd/go)
-test.timeout dpanic test binary after duration d (default 0, timeout disabled)
-test.trace filewrite an execution trace to file
-test.vverbose: print additional output
这篇关于Golang test编译使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!