Usage of ginkgo arguments using go test

Running ginkgo tests using go test is a neat way on integrating behavioural testing with go tests.

When using pass-through arguments or user defined arguments in ginkgo, they can passed in following way.

var life int

func init() {
	flag.IntVar(&life, "life", -1, "Meaning of Life!")
}

func TestString(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Run meaning of life suite")
}

var _ = Describe("Ultimate Question of Life, the Universe, and Everything", func() {
	Context("According to Deep Thought", func() {
		When("calculated over 7.5 million years", func() {
			It("should be correct", func() {
				fmt.Fprintln(GinkgoWriter, "Verifying ultimate question!")
				Expect(42).To(Equal(life), "Meaning of life not determined!")
			})
		})
	})
})

Can pass life variable using command.

ginkgo -- -life=42

To pass the same using go test

go test --args -life=42

A ginkgo argument can be passed in go tests, example passing -v for verbose.

go test --args -life=42 -ginkgo.v
comments powered by Disqus