Library for easy testing of Kubernetes deployments and operators using Fabric8 API.
- Automatic resource lifecycle - Every resource created via KubeResourceManager is automatically cleaned up after each test, whether it passes or fails
- Declarative testing - Use
@KubernetesTestfor 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.
See the Quickstart Guide to get your first Kubernetes test running in under 5 minutes.
| 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.
| 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 |
| Resource Types | Built-in K8s/OpenShift ResourceType list, readiness semantics, custom types |
| Resource Batches | Batch grouping, LIFO cleanup ordering, openBatch() usage |
| Configuration Reference | All env vars, system properties, YAML config file, and multi-context setup |
| Testing Guide | Unit tests, Fabric8 mock client, integration tests, CI checks |
| Architecture | Module structure, key abstractions, threading model, data flow |
| 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 |
See the Configuration Reference for the full variable list, resolution order (env var → system property → YAML file → default), YAML config file format, and multi-cluster setup.
Quick example — pass config directly via Maven:
./mvnw test -DKUBE_URL=https://api.my-cluster:6443 -DKUBE_TOKEN=my-token -DCLIENT_TYPE=oc- strimzi.io Strimzi Kafka operator - e2e
- strimzi.io Kafka access operator - e2e
- debezium.io Debezium Operator - e2e
- streamshub Streams E2E - e2e
- streamshub Streamshub MCP - streamshub-mcp
- streamshub StreamsHub Console for Apache Kafka® - console
- kroxylicious Kroxylicious, the snappy open source proxy for Apache Kafka® - kroxylicious