# Run all tests under pkg (requires client to be in $GOPATH/src/k8s.io)
godep go test ./pkg/...
# Run all tests in the pkg/api (but not subpackages)
godep go test ./pkg/api
```
### Stress running unit tests
Running the same tests repeatedly is one way to root out flakes.
You can do this efficiently.
```sh
cd kubernetes
# Have 2 workers run all tests 5 times each (10 total iterations).
hack/test-go.sh -p 2 -i 5
```
For more advanced ideas please see [flaky-tests.md](flaky-tests.md).
### Unit test coverage
Currently, collecting coverage is only supported for the Go unit tests.
To run all unit tests and generate an HTML coverage report, run the following:
```sh
cd kubernetes
KUBE_COVER=y hack/test-go.sh
```
At the end of the run, an the HTML report will be generated with the path printed to stdout.
To run tests and collect coverage in only one package, pass its relative path under the `kubernetes` directory as an argument, for example:
```sh
cd kubernetes
KUBE_COVER=y hack/test-go.sh pkg/kubectl
```
Multiple arguments can be passed, in which case the coverage results will be combined for all tests run.
Coverage results for the project can also be viewed on [Coveralls](https://coveralls.io/r/kubernetes/kubernetes), and are continuously updated as commits are merged. Additionally, all pull requests which spawn a Travis build will report unit test coverage results to Coveralls. Coverage reports from before the Kubernetes Github organization was created can be found [here](https://coveralls.io/r/GoogleCloudPlatform/kubernetes).
### Benchmark unit tests
To run benchmark tests, you'll typically use something like:
```sh
cd kubernetes
godep go test ./pkg/apiserver -benchmem -run=XXX -bench=BenchmarkWatch
```
This will do the following:
1.`-run=XXX` will turn off regular unit tests
* Technically it will run test methods with XXX in the name.
2.`-bench=BenchmarkWatch` will run test methods with BenchmarkWatch in the name
* See `grep -nr BenchmarkWatch .` for examples
3.`-benchmem` enables memory allocation stats
See `go help test` and `go help testflag` for additional info.