go get github.com/onsi/ginkgo/ginkgo
go get github.com/onsi/gomega
在git bash中cd到该目录
然后运行下ginkgo help,看下参数列表
Usage of ginkgo:
-a Force rebuilding of packages that are already up-to-date.
-afterSuiteHook string
Run a command when a suite test run completes
-asmflags string
Arguments to pass on each go tool asm invocation.
-blockprofilerate int
Control the detail provided in goroutine blocking profiles by calling runtime.SetBlockProfileRate with the given value. (default 1)
-buildmode string
Build mode to use. See 'go help buildmode' for more.
-compiler string
Name of compiler to use, as in runtime.Compiler (gccgo or gc).
-compilers int
The number of concurrent compilations to run (0 will autodetect)
-cover
Run tests with coverage analysis, will generate coverage profiles with the package name in the current directory.
-covermode string
Set the mode for coverage analysis.
-coverpkg string
Run tests with coverage on the given external modules.
-coverprofile string
Write a coverage profile to the specified file after all tests have passed.
-cpuprofile string
Write a CPU profile to the specified file before exiting.
-dryRun
If set, ginkgo will walk the test hierarchy without actually running anything. Best paired with -v.
-failFast
If set, ginkgo will stop running a test suite after a failure occurs.
-failOnPending
If set, ginkgo will mark the test suite as failed if any specs are pending.
-flakeAttempts int
Make up to this many attempts to run each spec. Please note that if any of the attempts succeed, the suite will not be failed. But any failures will still be recorded. (default 1)
-focus string
If set, ginkgo will only run specs that match this regular expression.
-gccgoflags string
Arguments to pass on each gccgo compiler/linker invocation.
-gcflags string
Arguments to pass on each go tool compile invocation.
-installsuffix string
A suffix to use in the name of the package installation directory.
-keepGoing
When true, failures from earlier test suites do not prevent later test suites from running
-ldflags string
Arguments to pass on each go tool link invocation.
-linkshared
Link against shared libraries previously created with -buildmode=shared.
-memprofile string
Write a memory profile to the specified file after all tests have passed.
-memprofilerate int
Enable more precise (and expensive) memory profiles by setting runtime.MemProfileRate.
-msan
Enable interoperation with memory sanitizer.
-n go test
Have go test print the commands but do not run them.
-noColor
If set, suppress color output in default reporter.
-nodes int
The number of parallel test nodes to run (default 1)
-noisyPendings
If set, default reporter will shout about pending tests. (default true)
-outputdir string
Place output files from profiling in the specified directory.
-p Run in parallel with auto-detected number of nodes
-pkgdir string
install and load all packages from the given dir instead of the usual locations.
-progress
If set, ginkgo will emit progress information as each spec runs to the GinkgoWriter.
-r Find and run test suites under the current directory recursively.
-race
Run tests with race detection enabled.
-randomizeAllSpecs
If set, ginkgo will randomize all specs together. By default, ginkgo only randomizes the top level Describe/Context groups.
-randomizeSuites
When true, Ginkgo will randomize the order in which test suites run
-regexScansFilePath
If set, ginkgo regex matching also will look at the file path (code location).
-seed int
The seed used to randomize the spec suite. (default 1471744764)
-skip string
If set, ginkgo will only run specs that do not match this regular expression.
-skipMeasurements
If set, ginkgo will skip any measurement specs.
-skipPackage string
A comma-separated list of package names to be skipped. If any part of the package's path matches, that package is ignored.
-slowSpecThreshold float
(in seconds) Specs that take longer to run than this threshold are flagged as slow by the default reporter. (default 5)
-stream
stream parallel test output in real time: less coherent, but useful for debugging (default true)
-succinct
If set, default reporter prints out a very succinct report
-tags string
A list of build tags to consider satisfied during the build.
-toolexec string
a program to use to invoke toolchain programs like vet and asm.
-trace
If set, default reporter prints out the full stack trace when a failure occurs
-untilItFails
When true, Ginkgo will keep rerunning tests until a failure occurs
-v If set, default reporter print out all specs as they begin.
-work
Print the name of the temporary work directory and do not delete it when exiting.
-x go test
Have go test print the commands.
生成一个测试套
$ ginkgo bootstrap
Generating ginkgo test suite bootstrap for go_test_go in:
go_test_go_suite_test.go
$ ginkgo generate
查看下生成的文件
$ ls -lrt
total 2
-rw-r--r-- 1 opama None 199 Aug 21 02:06 go_test_go_suite_test.go
-rw-r--r-- 1 opama None 162 Aug 21 02:07 go_test_go_test.go
可以在一个已有工程为其添加test文件
D:\workspace\hellogo\src\aaa>ginkgo generate
Generating ginkgo test for Aaa in:
aaa_test.go
D:\workspace\hellogo\src\aaa>go test
testing: warning: no tests to run
PASS
ok _/D_/workspace/hellogo/src/aaa 0.309s
var _ = Describe("Node", func() {
// Context("Context test",func() {
ret := node.GetNode("123");
result := comm.GetHttp("456");
It("just test suc", func() {
Expect(ret).Should(Equal(200));
Expect(result).Should(Equal("456"));
})
PIt("just test fail", func() {
Expect(ret).Should(Equal("123"));
Expect(result).Should(Equal("4566"));
})
// })
})
$ ginkgo
Running Suite: K8sdemo Suite
============================
Random Seed: 1472956009
Will run 1 of 2 specs
+
------------------------------
P [PENDING]
Node
D:/workspace/k8sdemo/src/node_test.go:27
just test fail
D:/workspace/k8sdemo/src/node_test.go:25
------------------------------
Ran 1 of 2 Specs in 0.000 seconds
SUCCESS! -- 1 Passed | 0 Failed | 1 Pending | 0 Skipped PASS
Running Suite: K8sdemo Suite
============================
Random Seed: 1472956139
Will run 1 of 2 specs
S
------------------------------
+ Failure [0.001 seconds]
Node
D:/workspace/k8sdemo/src/node_test.go:27
just test fail [It]
D:/workspace/k8sdemo/src/node_test.go:25
Expected
<int>: 200
to equal
<string>: 123
Summarizing 1 Failure:
[Fail] Node [It] just test fail
D:/workspace/k8sdemo/src/node_test.go:23
Ran 1 of 2 Specs in 0.001 seconds
FAIL! -- 0 Passed | 1 Failed | 0 Pending | 1 Skipped --- FAIL: TestK8sdemo (0.00s)
FAIL
Ginkgo ran 1 suite in 2.8093489s
Test Suite Failed