Skip to content

skodjob/kubetest4j

Kubetest4j

Library for easy testing of Kubernetes deployments and operators using Fabric8 API.

OpenSSF Scorecard Build License Quality Gate Status GitHub Release Maven Central Version

Key Features

  • Automatic resource lifecycle - Every resource created via KubeResourceManager is automatically cleaned up after each test, whether it passes or fails
  • Declarative testing - Use @KubernetesTest for annotation-driven namespace management, dependency injection, and log collection (details)
  • Multi-cluster support - Test across multiple Kubernetes/OpenShift clusters simultaneously with per-context resource managers
  • Built-in clients - Auto-configured Fabric8 Kubernetes client and kubectl/oc CLI wrapper
  • Log & metrics collection - Collect pod logs on failure (log-collector) and scrape Prometheus metrics (metrics-collector)
  • Visual test separation - ASCII separators in test logs for better readability
  • Cluster utilities - Helpers for pod readiness, job management, OLM operations, and more

Choose your approach:

  • @KubernetesTest (junit-extension) - Declarative, batteries-included. Best for most users.
  • @ResourceManager (core) - Maximum control, custom setup. Use individual modules directly.

Getting Started

See the Quickstart Guide to get your first Kubernetes test running in under 5 minutes.

Available modules

Module Artifact Description
Core kubetest4j Resource manager, clients, utilities
K8s Resources kubernetes-resources ResourceType implementations for native K8s resources
OpenShift Resources openshift-resources ResourceType implementations for OpenShift/OLM resources
JUnit Extension junit-extension Declarative @KubernetesTest annotation with DI and log collection
Log Collector log-collector Pod log/description/YAML collection utility
Metrics Collector metrics-collector Prometheus metrics scraping from pods

All modules are published to Maven Central under io.skodjob.kubetest4j.

Documentation

Document Description
Quickstart Guide Get started in 5 minutes (Maven & Gradle)
Core Module KubeResourceManager, clients, multi-context, ResourceTypes, utilities
JUnit Extension Full @KubernetesTest reference, annotations, multi-context, log collection
Log Collector Pod log collection configuration and usage
Metrics Collector Prometheus metrics scraping
Comparison with Alternatives How kubetest4j compares to Testcontainers, Fabric8, Arquillian, JKube
Examples (core) Integration test examples using @ResourceManager
Examples (JUnit ext) Integration test examples using @KubernetesTest

Config environment variables

Variable Description
ENV_FILE Path to YAML file with environment variable values
KUBE_URL URL of the cluster (API URL)
KUBE_TOKEN Token for cluster access
KUBECONFIG Path to kubeconfig (overrides URL/token)
CLIENT_TYPE Switch between kubectl or oc (default: kubectl)
KUBE_URL_XXX URL for additional cluster (suffix like PROD, DEV, TEST)
KUBE_TOKEN_XXX Token for additional cluster
KUBECONFIG_XXX Kubeconfig for additional cluster

Adopters

Maintainers

About

Library for easy testing of kubernetes deployments and operators using fabric8 api.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors

Languages