I’ve the following project structure and I want to run go test exclude option to run the test
e.g. Command to Run all tests except the test in the cmd
package (I’ve more then 3 packages , the struct below is a simple example)
myGithubProject/ |---- cmd |---- -command |---- -hello.go |---- -hello_test.go |---- internal |---- -fs.go |---- -fs.go |---- -fs_test.go |---- -log |---- -log.go |---- -log_test.go main.go
If you have a hierarchy like that, you may specify the sibling folder to test (and recurse down) like this:
go test internal/...
If this is not feasible to you (e.g. you have many siblings of cmd
, or you have many subfolders inside cmd
which you do want to test), you may use build constraints to achieve what you want.
For example, add an exclusion of a donttestme
build tag to the hello_test.go
file (the first line):
// +build !donttestme
And then when you specify this tag when testing, files that exclude this build tag will not be considered (will be skipped):
go test -tags donttestme <somepackages>