Responsive

Streamlined Kubernetes Testing: How Testcontainers and Testkube Work Together

Published
June 6, 2025
Atulpriya Sharma
Sr. Developer Advocate
InfraCloud Technologies
Share on X
Share on LinkedIn
Share on Reddit
Share on HackerNews
Copy URL

Table of Contents

Want a Personalized Feature Set Demo?

Unlock Better Testing Workflows in Kubernetes — Try Testkube for Free

Subscribe to our monthly newsletter to stay up to date with all-things Testkube.

You have successfully subscribed to the Testkube newsletter.
You have successfully subscribed to the Testkube newsletter.
Oops! Something went wrong while submitting the form.
Last updated
June 6, 2025
Atulpriya Sharma
Sr. Developer Advocate
InfraCloud Technologies
Share on X
Share on LinkedIn
Share on Reddit
Share on HackerNews
Copy URL

Table of Contents

Testing has long been a reactive process in most organizations, triggered by code commits or schedules. While Kubernetes transformed how we deploy our applications and automated many of these activities, testing still needs to catch up. 

In our previous article on Continuous Testing for the Cloud-Native Era, we discussed the mismatch between modern deployment practices and legacy testing methods, which creates several challenges, including environment inconsistencies, poor visibility into test coverage, and costly debugging sessions.

Such technical challenges impact business outcomes with delayed releases, reduced developer productivity, and increased infrastructure costs. As a result, a simple deployment that should have taken just a few minutes can take days or months to complete.

In this article, we will look at two complementary tools that can address these challenges: Testcontainers, which provide developers with greater control over containerized dependencies in their tests, and Testkube, which provides a cloud-native and vendor-agnostic platform that treats tests as versioned resources. 

Testcontainers -  Developer’s Perspective

Testcontainers is an open source library that allows developers to spin up temporary, lightweight versions of services like databases, message queues, and browsers for testing purposes. At its core, Testcontainers leverages Docker to spin up real service containers programmatically during test execution.

It enables developers to write tests that rely on external services without mocks or complex setup scripts. It supports multiple programming languages, including Java, Go, Python, Node.js, and  .NET.

For instance, developers can spin up a PostgreSQL container and use it for testing without actually creating one.

import pytest
from testcontainers.postgres import PostgresContainer

def test_postgres_connection():

	# This automatically pulls and starts a PostgreSQL container
	with PostgresContainer("postgres:14.1") as postgres:

    	# Get connection details from the running container
    	connection_url = postgres.get_connection_url()
   	 
    	# Connect to the database and run your tests
    	# No need for mocks or shared test databases!
    	db = connect_to_database(connection_url)
    	result = db.execute("SELECT 1")
    	assert result == 1

With each execution, Testcontainer guarantees a fresh, isolated container that mimics the actual service, ensuring reliable and consistent test results. 

How Does It Fit Into Existing Workflows?

Due to their nature and seamless integration with various tools, Testcontainers fit in well with existing developer workflows:

  • Local development: Developers can now run the same test on their machines that the CI will run with the same configuration and dependencies. 
  • Continuous integration: Testcontainers can automatically provision the required services for each test run without a pre-configured environment, thus simplifying the CI configuration. 
  • Test-driven development: These enable TDD by making it easier to write integration tests earlier in the development cycle without waiting for the infrastructure team to provide testing environments. 

Benefits of Testcontainers

Testcontainers became a popular choice among developers for the following reasons:

  • Reality over mocks: It eliminates the creation of simulated services and instead creates real dependencies to test on, eliminating the “works on my machine” syndrome. This helps identify integration issues that mocks often miss. 
  • Simplicity: Testcontainers abstract away the complexity of managing containers, making it accessible to developers. 
  • Ephemeral nature: Each test run starts with a clean slate, preventing flaky tests caused by shared tests. 
  • Language native support: Testcontainers integrates directly with native testing frameworks like pytest, unit test, and Go’s testing package, simplifying developers' workflows. 

Testkube: The Platform Perspective

Testcontainers provide developers with a simpler way to deal with dependencies. However, they cannot test Kubernetes-specific features like ConfigMaps, Ingress objects, or other Kubernetes resources. Further, enterprise Kubernetes deployments demand capabilities beyond just developer-centric tools. That’s where Testkube comes into play: to provide a comprehensive platform for testing cloud native applications. 

Let's understand how Testkube specifically complements the developer-focused Testcontainers approach:

  • It orchestrates test execution across different environments, mirroring production with identical Kubernetes resources
  • Configure the execution of tests and their dependencies in a single yaml file - as a Kubernetes CRD.
  • Get consolidated test results and metrics with a built-in dashboard
  • Integrates with CI/CD tools like GitHub Actions, Jenkins, and ArgoCD, also with CI tools like CircleCI

Testkube provides a standalone open source agent that is deployed in your Kubernetes infrastructure for vendor-agnostic test execution and a commercial control plane that can be used to manage multiple agents with additional features for parallelization, orchestration, RBAC, centralized troubleshooting, and reporting, etc.

Enterprise setups need unified visibility that individual tools can't provide. Testkube offers a centralized dashboard for monitoring test execution across teams and services, along with standardized reporting formats.

Combining Forces: Testcontainers + Testkube

Combining Testcontainers with Testkube allows you to create a continuous testing pipeline that spans from development environments to production clusters. It addresses the complete spectrum of testing needs from providing developers with the simplicity they require to giving platform teams the enterprise-scale orchestration they demand.

Developers can start by using Testcontainers for local testing, ensuring dependencies are properly containerized and tests are environment-agnostic. These same tests can then be packaged and deployed to Kubernetes via Testkube, orchestrating their execution within the cluster. Thus, tests written once can be executed across different environments with minimal modification, ensuring consistency throughout the delivery pipeline.

For instance, below is a TestWorkflow showing an Ollama HuggingFace test with Gradle and Testcontainers Workflow.

kind: TestWorkflow
apiVersion: testworkflows.testkube.io/v1
metadata:
 name: gradle-with-testcontainers
 namespace: testkube
spec:
 content:
   git:
     uri: 'https://github.com/testcontainers/testcontainers-java'
     revision: main
 container:
   workingDir: /data/repo/examples/ollama-hugging-face
   resources:
     requests:
       cpu: 512m
       memory: 512Mi
 services:
   dind:
     logs: always
     timeout: 5m
     image: 'docker:27.4.0-dind'
     env:
       - name: DOCKER_TLS_CERTDIR
     securityContext:
       privileged: true
     readinessProbe:
       tcpSocket:
         port: 2375
 steps:
   - name: Run tests
     run:
       image: 'gradle:8.5.0-jdk11'
       env:
         - name: TESTKUBE_GRADLE
           value: 'true'
         - name: DOCKER_HOST
           value: 'tcp://{{ services.dind.0.ip }}:2375'
       command:
         - gradle
         - '--no-daemon'
         - test
     artifacts:
       paths:
         - reports/**/*
         - test-results/**/*

Read our Testcontainer document to learn more about using Testkube with Testcontainer. 

How Both Tools Complement Each Other

Testcontainers and Testkube form a natural partnership, with each tool addressing distinct but complementary needs:

Testcontainers excels at:

  • Providing containerized dependencies for isolated testing
  • Integrating directly with developer IDEs and testing frameworks
  • Enabling fast, local execution of tests with real dependencies
  • Supporting the early stages of the development lifecycle

Testkube specializes in:

  • Orchestrating tests within Kubernetes environments
  • Managing test execution at scale across multiple teams
  • Providing centralized reporting and visibility
  • Supporting later stages of testing, including pre-production validation

Together, they create a comprehensive testing strategy that leverages the strengths of both approaches, eliminating gaps in your testing coverage.

Scenarios Where the Combined Approach Shines

Using Testcontainers and Testkube together can help you excel in different areas, like:

  • Complex Microservices Testing: When testing interactions between different services, Testcontainers simulate dependencies during development, while Testkube can orchestrate comprehensive integration tests in environments that mirror production.
  • Real-World Simulation: Using Testcontainers with Testkube ensures tests run against realistic dependencies at every stage—from containerized versions in development environments to actual Kubernetes-deployed services in production.
  • CI/CD Pipeline Integration: As code progresses through the pipeline, the same core tests can be executed in progressively more production-like environments, with Testcontainers handling early stages and Testkube managing the later stages.

Addressing Enterprise Concerns With This Combined Approach

Enterprise organizations face numerous challenges implementing Kubernetes at scale. These include the scalability of testing infrastructure, security risks in containerized environments, compliance with regulatory frameworks, and efficient resource utilization.

That’s where the combined synergy of Testcontainers and Testkube comes in, addressing these challenges through a comprehensive testing approach. 

Efficient Scaling

The combined approach uses Kubernetes capabilities to distribute tests across the cluster based on priority and requirements. Testkube enables the concurrent execution of TestWorkflows and provides configurable options through its built-in parallelization capabilities to run multiple tests simultaneously. This architecture supports efficient scaling by running test executors across multiple nodes, spinning up additional pods during peak periods, and scaling down during lean periods.

Secured Testing

Testcontainers execute within defined security contexts, such as non–root users and read–only file systems, while Testkube provides support for Role-Based Access Control (RBAC) to help you enforce how members of an Organization have access to Environments and their Resources. This multi-layered approach ensures isolation and secure execution of tests in your CI pipeline. 

In addition, Testkube runs any testing tool from inside your Kubernetes clusters; you do not need to make your applications accessible to external networks for testing purposes. It also integrates with tools like OWASP Zap, which allows you to scan, test, and identify vulnerabilities across the application, including the front-end, back-end, and APIs. 

Compliance and Audit

Testkube maintains detailed records of all test executions, providing audit evidence for compliance requirements. By treating tests as Kubernetes resources, changes are version-controlled and traceable, supporting change management requirements. Testcontainers, on the other hand, provide isolated, disposable environments for running tests. They allow for controlled testing, allow developers to better track the dependencies and configurations used in their tests, and help in audits and compliance reviews.

Cost Optimization

Testcontainers are ephemeral by nature and are provisioned and reclaimed dynamically. They ensure that containers are destroyed regardless of whether tests are executed successfully or fail, keeping costs in check. With Testkube, tests are Kubernetes resources, which makes it easy for organizations to track resource consumption by team or project, enabling accurate cost allocation and management. 

By addressing these enterprise concerns, the combined approach of using Testcontainers with Testkube enables organizations to implement robust Kubernetes testing at scale without compromising on security, compliance, or cost efficiency. 

Summary

Using Testkube and Testcontainers creates a powerful and comprehensive testing strategy for Kubernetes environments. It bridges the gap between development simplicity and enterprise requirements. Testcontainers provide developers with consistent and containerized testing environments, while Testkube extends these capabilities with Kubernetes native orchestration, centralized management, and platform-level controls. 

By adopting this approach, teams can accelerate release cycles, reduce failures, and build greater confidence in their Kubernetes deployments.

Ready to transform your Kubernetes testing strategy? Try Testkube today and experience how it complements your existing Testcontainers workflow to deliver enterprise-grade testing capabilities. You can also reach out to the Testkube team, plus a vibrant community of fellow Kubernetes testers is on Slack

About Testkube

Testkube is a test execution and orchestration framework for Kubernetes that works with any CI/CD system and testing tool you need, empowering teams to deliver on the promise of agile, efficient, and comprehensive testing programs by leveraging all the capabilities of K8s to eliminate CI/CD bottlenecks, perfecting your testing workflow. Get started with Testkube's free trial today.