TExcelTAD
Home › Kubernetes Packaging: Helm & Kustomize › Chart Tests with helm test

Chart Tests with helm test

helm install succeeding means the API server accepted the objects. It doesn't mean linkly answers HTTP requests. A chart test is a Pod (or Job) that Helm runs on demand against an installed release, and whose exit code says whether the release works.

Writing a test

Tests live under templates/tests/ by convention and carry the hook annotation helm.sh/hook: test. linkly's test calls the readiness endpoint through the Service, exactly the path real traffic takes inside the cluster:

bash · try it yourself
mkdir -p linkly/templates/tests && cd linkly
printf 'apiVersion: v2\nname: linkly\nversion: 0.7.0\n' > Chart.yaml
printf 'service:\n  port: 80\n' > values.yaml
cat > templates/service.yaml <<'EOF'
apiVersion: v1
kind: Service
metadata:
  name: {{ .Release.Name }}-linkly
spec:
  selector: {app.kubernetes.io/instance: {{ .Release.Name }}}
  ports: [{name: http, port: {{ .Values.service.port }}, targetPort: 8080}]
EOF
cat > templates/tests/test-readyz.yaml <<'EOF'
apiVersion: v1
kind: Pod
metadata:
  name: {{ .Release.Name }}-test-readyz
  annotations:
    helm.sh/hook: test
    helm.sh/hook-delete-policy: before-hook-creation
spec:
  restartPolicy: Never
  securityContext: {runAsNonRoot: true, runAsUser: 65532}
  containers:
    - name: curl
      image: curlimages/curl:8.17.0
      args: ["--fail", "--silent", "--show-error", "--max-time", "5",
             "http://{{ .Release.Name }}-linkly:{{ .Values.service.port }}/readyz"]
EOF
helm template web . | grep -E '^# Source|^kind|readyz"'
echo "--- --skip-tests:"
helm template web . --skip-tests | grep -E '^# Source'
helm template web . | kubeconform -strict -summary
# Source: linkly/templates/service.yaml
kind: Service
# Source: linkly/templates/tests/test-readyz.yaml
kind: Pod
             "http://web-linkly:80/readyz"]
--- --skip-tests:
# Source: linkly/templates/service.yaml
Summary: 2 resources found parsing stdin - Valid: 2, Invalid: 0, Errors: 0, Skipped: 0

helm template includes test hooks unless you pass --skip-tests, the same as other hooks. Keep that in mind if a GitOps tool applies the rendered output: unless the tool understands Helm's hook annotations, it creates the test Pod as a normal object. Render with --skip-tests for such tools, or check how they treat hooks (GitOps).

Running tests (sample)

This needs a cluster. helm test creates every test hook of the release, waits for each to finish, and reports. Helm 4 output looks like this:

bash
helm test web -n linkly --logs
text
NAME: web
LAST DEPLOYED: Tue Jan 13 10:42:07 2026
NAMESPACE: linkly
STATUS: deployed
REVISION: 4
DESCRIPTION: Upgrade complete
TEST SUITE:     web-test-readyz
Last Started:   Tue Jan 13 10:44:31 2026
Last Completed: Tue Jan 13 10:44:35 2026
Phase:          Succeeded

POD LOGS: web-test-readyz
ok

A failing test prints Phase: Failed and makes helm test exit non-zero, so a pipeline can run helm upgrade --install … && helm test … and stop on failure. --logs prints the test Pods' logs, which is the only place the failure reason shows up. --filter name=web-test-readyz runs a single test.

What makes a good chart test

  • Smoke, not suites. A chart test checks that this installation is wired correctly: the Service selects the Pods, the route answers, the app can reach its database (/readyz checks it). Functional tests of the application belong in the app's CI.
  • Fast and self-contained. Use a small pinned image (curlimages/curl:<version>, busybox:<version>), a --max-time, and restartPolicy: Never.
  • Safe. Tests run in production namespaces. Never write data you can't clean up, and run as non-root like any other Pod.
  • Deleted afterwards. before-hook-creation (or hook-succeeded) keeps test Pods from piling up.

Tests at other levels

helm test needs a running release. Two other kinds of test catch problems earlier and run without a cluster; both appear in the Toolkit:

Level Tool Checks
template unit tests the helm-unittest plugin "with autoscaling.enabled=true, the Deployment has no replicas" (assertions on rendered YAML)
render + schema helm lint, helm template | kubeconform valid YAML, valid Kubernetes objects (Validating with kubeconform)
install + test ct install (chart-testing) in a kind cluster, then helm test the chart really installs and works

Test yourself

What makes a Pod a chart test?

  1. Living in templates/tests/
  2. The annotation helm.sh/hook: test
  3. The name ending in -test
  4. A label test=true

How do you keep test Pods out of helm template output that a GitOps tool will apply?

  1. --no-hooks or --skip-tests
  2. --dry-run
  3. --hide-notes
  4. You can't

What should a chart test verify?

  1. Every feature of the application
  2. That this release is wired correctly: Service, routing, dependencies
  3. That Helm is installed
  4. Unit tests of the Go code