Just run single test instead of the whole suite?

Given a test:

func Test_myTest() {
    //...
}

Run only that test with:

go test -run Test_myTest path/to/pkg/mypackage

In case someone that is using Ginkgo BDD framework for Go will have the same problem, this could be achieved in that framework by marking test spec as focused (see docs), by prepending F before It, Context or Describefunctions.

So, if you have spec like:

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

You rewrite it as:

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

And it will run exactly that one spec:

[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

Simple and reliable:

go test -run TestMyFunction ./...

More on ./... : https://stackoverflow.com/a/28031651/5726621


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

-run regexp
    Run only those tests and examples matching the regular
    expression.

Tags:

Go