go get github.com/onsi/ginkgo/v2/ginkgo
go install github.com/onsi/ginkgo/v2/ginkgo
go get github.com/onsi/gomega
mkdir test
cd test
ginkgo bootstrap
ginkgo常用的模块是It、Describe、BeforeEach、AfterEach、BeforeSuite、AfterSuite。
It指定单个测试用例。
Describe归类测试用例。
BeforeEach在每个测试例执行前执行。
AfterEach在每个测试例执行后执行。
BeforeSuite在该测试集执行前执行。
AfterSuite在该测试集执行后执行。
package test_test
import (
"testing"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
func TestTest(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Test Suite")
}
var count int = 0
var _ = BeforeSuite(func() {
count++
Expect(count).To(Equal(1))
})
var _ = AfterSuite(func() {
count = 0
Expect(count).To(Equal(0))
})
var _ = Describe("count test", func() {
BeforeEach(func() {
count++
})
AfterEach(func() {
count--
})
Describe("count negative test", func() {
It("count must negative", func() {
count -= 10
Expect(count < 0).To(Equal(true))
})
})
})
指定测试类执行
ginkgo --focus="count negative test"
标签:count,onsi,github,ginkgo,测试用例,func,test,编写
From: https://www.cnblogs.com/WJQ2017/p/18403067