How to Run Tests for Kubernetes
This guide provides steps on how to run tests for the Kubernetes project.
Running All Tests
To run all tests, execute the following command from the top level of the Kubernetes repository:
make test
Running Specific Tests
To run a subset of tests, use the WHAT
argument with the make test
command. For example, to run tests in the pkg/kubelet
directory, execute:
make test WHAT=./pkg/kubelet
Running End-to-End (E2E) Tests
To run the Node E2E tests, execute:
make test-e2e-node
Running Command-Line Integration Tests
To run the entire suite of command-line integration tests, execute:
make test-cmd
To run a specific set of command-line tests, use the WHAT
argument. For example, to run the run_deployment_tests
and run_impersonation_tests
functions, execute:
make test-cmd WHAT="deployment impersonation"
Running Benchmark Tests
To run benchmark tests, use the hack/benchmark-go.sh
script. For example, to run benchmarks for the pkg/kubelet
directory, execute:
hack/benchmark-go.sh WHAT=./pkg/kubelet
Running Unit Tests
To run unit tests, use the go test
command. For example, to run the unit tests in the test/e2e/framework/internal/unittests/list-tests
directory, execute:
go test test/e2e/framework/internal/unittests/list-tests
Note: The go test
command may require additional arguments depending on the specific test suite.
Running Tests with Coverage
To run tests with code coverage, set the KUBE_COVER
environment variable to y
before running the make test
command. For example:
KUBE_COVER=y make test
Cleaning Build Artifacts
To remove all build artifacts, execute:
make clean
This command will run the build/make-clean.sh
and hack/make-rules/clean.sh
scripts.
Additional Notes
- The
Makefile
file contains various targets for building and running tests. Refer to theMakefile
file for more information on the available targets and options. - The
hack/make-rules
directory contains additional make rules used for testing. - The
test/e2e/framework/internal/unittests/list-tests/listtests_test.go
file demonstrates how to run unit tests. - The
test/cmd/README.md
file provides instructions for adding new command-line integration tests. - The
hack/benchmark-go.sh
script provides details on how to run benchmark tests. - The
test/e2e/node/README.md
file explains the use of Node end-to-end tests. - The
test/e2e/framework/internal/unittests/list-tests/listtests_test.go
file demonstrates how to run unit tests.