Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to `go test` all tests in my project?

Tags:

testing

go

People also ask

How do you run all tests in go?

This should run all tests in current directory and all of its subdirectories: $ go test ./... This should run all tests for given specific directories: $ go test ./tests/... ./unit-tests/... ./my-packages/...

How do you run go test locally?

To run your tests in this mode, run go test in your project's root directory. In the package list mode, go test compiles and tests each package listed as arguments to the command. If a package test passes, go test prints only the final 'ok' summary line.


This should run all tests in current directory and all of its subdirectories:

$ go test ./...

This should run all tests for given specific directories:

$ go test ./tests/... ./unit-tests/... ./my-packages/...

This should run all tests with import path prefixed with foo/:

$ go test foo/...

This should run all tests import path prefixed with foo:

$ go test foo...

This should run all tests in your $GOPATH:

$ go test ...

From Go 1.9 onwards, use

go test ./...

In Go 1.6 through 1.8, the ./... matched also the vendor directory. To skip vendored packages, you'd use

go test $(go list ./... | grep -v /vendor/)

Sources: https://github.com/golang/go/issues/11659, https://github.com/golang/go/issues/14417, https://github.com/go-lang-plugin-org/go-lang-idea-plugin/issues/2366, @nickgrim's comment.


Folder Structure

ProjectName/folderName1/file_test.go
ProjectName/folderName2/file1_test.go
ProjectName/folderName3/file2_test.go

go test command Command

   ProjectName$ go test -v ./...
    ProjectName$ go test  ./...
    ProjectName$ go test -cover ./...

Coverage Report for the Entire Project

ok      ProjectName/folderName1 10%
ok      ProjectName/folerName2  90%
ok      ProjectName/folerName2  85%