1

Consider a multi binary project with the following structure.

.
├── bin1
│   ├── config
│   │   ├── config.go
│   │   └── config_test.go
│   └── utils
│       ├── utils.go
│       └── utils_test.go
├── bin2
│   ├── config
│   │   ├── config.go
│   │   └── config_test.go
│   └── utils
│       ├── utils.go
│       └── utils_test.go
├── cmd
│   ├── bin1
│   │   └── bin1.go
│   ├── bin2
│   │   └── bin2.go
│   └── bin3
│       └── bin3.go
├── go.mod
├── go.sum
└── shared
    ├── db
    │   ├── db.go
    │   └── db_test.go
    ├── model
    │   ├── modela.go
    │   ├── modela_test.go
    │   ├── modelb.go
    │   └── modelb_test.go
    └── utils
        ├── utils.go
        └── utils_test.go

This project has three binaries bin1, bin2 and bin3. Packages in the /shared directory (e.g. package shareddb, sharedmodel and sharedutils) are shared with binary specific packages (e.g. package bin1config, bin1utils in /bin1 directory and package bin2config, bin2utils in /bin2 directory).

How can we run

  • all the unit tests in this project altogether?

  • all the tests in a package (e.g. in shared/model)?

  • each tests separately?

I attempted the following.

  • Running go test from the project root resulted in no Go files in /projectroot.
kexic63212
  • 19
  • 2

1 Answers1

2
# run all tests
go test ./...

# run all tests under a specific directory (including subdiretories)
go test ./bin2/...

# test package located in specific directory
go test ./shared/model

# test package that has specific import path
go test projectroot/shared/model

# test package in current working directory
go test

# ditto
go test .

# test package in parent directory
go test ..

# run a specific test within the package under test
go test -run=X

# run a specific sub-test within the package under test
go test -run=X/Y

For more details on the go test command, see Test packages.

For more details on the [packages] argument to go test, see Packge lists and patters.

For more details on the testing flags, see Testing flags.

mkopriva
  • 35,176
  • 4
  • 57
  • 71