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