Running the same tests repeatedly is one way to root out flakes.
Running the same tests repeatedly is one way to root out flakes.
You can do this efficiently.
You can do this efficiently.
```sh
```sh
cd kubernetes
# Have 2 workers run all tests 5 times each (10 total iterations).
# Have 2 workers run all tests 5 times each (10 total iterations).
hack/test-go.sh -p 2 -i 5
hack/test-go.sh -p 2 -i 5
```
```
...
@@ -117,43 +148,39 @@ Currently, collecting coverage is only supported for the Go unit tests.
...
@@ -117,43 +148,39 @@ 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:
To run all unit tests and generate an HTML coverage report, run the following:
```sh
```sh
cd kubernetes
KUBE_COVER=y hack/test-go.sh
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.
At the end of the run, an 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:
To run tests and collect coverage in only one package, pass its relative path
under the `kubernetes` directory as an argument, for example:
```sh
```sh
cd kubernetes
KUBE_COVER=y hack/test-go.sh pkg/kubectl
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.
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
### Benchmark unit tests
To run benchmark tests, you'll typically use something like:
To run benchmark tests, you'll typically use something like:
```sh
```sh
cd kubernetes
go test ./pkg/apiserver -benchmem-run=XXX -bench=BenchmarkWatch
go test ./pkg/apiserver -benchmem-run=XXX -bench=BenchmarkWatch
```
```
This will do the following:
This will do the following:
1.`-run=XXX` will turn off regular unit tests
1.`-run=XXX` is a regular expression filter on the name of test cases to run
* Technically it will run test methods with XXX in the name.
2.`-bench=BenchmarkWatch` will run test methods with BenchmarkWatch in the name
2.`-bench=BenchmarkWatch` will run test methods with BenchmarkWatch in the name
* See `grep -nr BenchmarkWatch .` for examples
* See `grep -nr BenchmarkWatch .` for examples
3.`-benchmem` enables memory allocation stats
3.`-benchmem` enables memory allocation stats
See `go help test` and `go help testflag` for additional info.
See `go help test` and `go help testflag` for additional info.
## Integration tests
## Integration tests
* Integration tests should only access other resources on the local machine
* Integration tests should only access other resources on the local machine
...
@@ -163,26 +190,24 @@ See `go help test` and `go help testflag` for additional info.
...
@@ -163,26 +190,24 @@ See `go help test` and `go help testflag` for additional info.
* The preferred method of testing multiple scenarios or inputs
* The preferred method of testing multiple scenarios or inputs
is [table driven testing](https://github.com/golang/go/wiki/TableDrivenTests)
is [table driven testing](https://github.com/golang/go/wiki/TableDrivenTests)