Just run a single test instead of the whole package?

I have a test suite for the Go package that implements a dozen tests. Sometimes one of the tests in a package fails, and I would like to re-run this test individually to save time in the debugging process. Is this possible, or should I write a separate file for this each time?

+7
go
source share
2 answers

Use the go test -run to run a specific test. The flag is documented in the go tool testing flags section documentation:

 -run regexp Run only those tests and examples matching the regular expression. 
+17
source share

In case someone using the Ginkgo BDD infrastructure for Go has the same problem, this can be achieved in this structure by marking the test specification as focused ( see documents ), adding F before that, Context or Describe functions.

So, if you have a specification:

  It("should be idempotent", func() { 

You rewrite it as:

  FIt("should be idempotent", func() { 

And it will work with just one specification:

 [Fail] testing Migrate setCurrentDbVersion [It] should be idempotent ... Ran 1 of 5 Specs in 0.003 seconds FAIL! -- 0 Passed | 1 Failed | 0 Pending | 4 Skipped 
+2
source share

All Articles