Skip to content

Commit 4ae5e6f

Browse files
authored
Merge pull request #4862 from brianpursley/kubernetes-90763
Update Testing Guide to clarify how to use go test as an alternative to make test
2 parents 90ff85a + 5267030 commit 4ae5e6f

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

contributors/devel/sig-testing/testing.md

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,6 @@ passing, so it is often a good idea to make sure the e2e tests work as well.
4848
cd kubernetes
4949
make test # Run all unit tests.
5050
```
51-
If you have `GOPATH` set up correctly, you can
52-
also just use `go test` directly.
53-
54-
```sh
55-
cd kubernetes
56-
go test ./... # Run all unit tests
57-
```
58-
59-
The remainder of this documentation presumes that you use `Make` as an
60-
entry point, but remember that the ability to use `go test` exists should you
61-
desire.
6251

6352
If any unit test fails with a timeout panic (see [#1594](https://github.com/kubernetes/community/issues/1594)) on the testing package, you can increase the `KUBE_TIMEOUT` value as shown below.
6453

@@ -80,12 +69,6 @@ added automatically to these:
8069
make test WHAT=./pkg/kubelet # run tests for pkg/kubelet
8170
```
8271

83-
Expressed strictly with `go test`, the above command is equivalent to the following:
84-
85-
```sh
86-
go test ./pkg/kubelet
87-
```
88-
8972
To run tests for a package and all of its subpackages, you need to append `...`
9073
to the package path:
9174

@@ -119,12 +102,6 @@ make test WHAT=./pkg/apis/core/validation GOFLAGS="-v" KUBE_TEST_ARGS='-run ^Tes
119102
make test WHAT=./pkg/apis/core/validation GOFLAGS="-v" KUBE_TEST_ARGS="-run ValidatePod\|ValidateConfigMap$"
120103
```
121104

122-
Or if we are using `go test` as our entry point, we could run:
123-
124-
```sh
125-
go test ./pkg/apis/core/validation -v -run ^TestValidatePods$
126-
```
127-
128105
For other supported test flags, see the [golang
129106
documentation](https://golang.org/cmd/go/#hdr-Testing_flags).
130107

@@ -171,12 +148,6 @@ To run benchmark tests, you'll typically use something like:
171148
make test WHAT=./pkg/scheduler/internal/cache KUBE_TEST_ARGS='-benchmem -run=XXX -bench=BenchmarkExpirePods'
172149
```
173150

174-
Alternatively, to express in pure Go, you could write the following:
175-
176-
```sh
177-
go test ./pkg/scheduler/internal/cache -benchmem -run=XXX -bench=Benchmark
178-
```
179-
180151
This will do the following:
181152

182153
1. `-run=XXX` is a regular expression filter on the name of test cases to run.
@@ -189,6 +160,36 @@ This will do the following:
189160

190161
See `go help test` and `go help testflag` for additional info.
191162

163+
### Run unit tests using go test
164+
165+
You can optionally use `go test` to run unit tests. For example:
166+
167+
```sh
168+
cd kubernetes
169+
170+
# Run unit tests in the kubelet package
171+
go test ./pkg/kubelet
172+
173+
# Run all unit tests found within ./pkg/api and its subdirectories
174+
go test ./pkg/api/...
175+
176+
# Run a specific unit test within a package
177+
go test ./pkg/apis/core/validation -v -run ^TestValidatePods$
178+
179+
# Run benchmark tests
180+
go test ./pkg/scheduler/internal/cache -benchmem -run=XXX -bench=Benchmark
181+
```
182+
183+
When running tests contained within a staging module,
184+
you first need to change to the staging module's subdirectory and then run the tests, like this:
185+
186+
```sh
187+
cd kubernetes/staging/src/k8s.io/kubectl
188+
189+
# Run all unit tests within the kubectl staging module
190+
go test ./...
191+
```
192+
192193
## Integration tests
193194

194195
Please refer to [Integration Testing in Kubernetes](integration-tests.md).

0 commit comments

Comments
 (0)