Responsive

Getting Started with Test Workflows For Kubernetes Testing

Getting Started with Test Workflows For Kubernetes Testing

Last updated
May 14, 2024
Bruno Lopes
Product Leader
Testkube

Table of Contents

Share on X
Share on LinkedIn
Share on Reddit
Share on HackerNews
Copy URL

Start Using Testkube for Free Today

Testing in Kubernetes is complicated. Configuring your testing tools to work with Kubernetes, giving your tests access to the cluster, and running and debugging them is a significant challenge. Developers often have to deal with multiple testing tools, each with its own reporting format, making it difficult to get a complete picture of test results. 

Fortunately, tools like Testkube provide developers with a unified testing framework built for Kubernetes to simplify and streamline the entire testing process. Testkube has evolved, and in this blog post, we’ll look at Test Workflows and how they can transform testing in Kubernetes. 

Running Tests with Testkube Executors

Since its inception, Testkube has evolved greatly, not only in terms of new feature additions but also improvement in the way it helps you test your applications. Executors in Testkube were the initial approach to running tests on Kubernetes. Let us look at the types of test executors in Testkube:

  • Test Executors: Each test in Testkube corresponds to a single executor object. Depending on the type of test - Postman, Cypress, curl, etc. - different executors are installed on your cluster to enable you to run those specific tests. Testkube supports several test types out of the box, which means you can simply bring your existing tests and run them with Testkube. 
  • Container Executors: Container executors are helpful when you have a test type that Testkube does not support out of the box. For instance, Pytest is not supported by TestKube out of the box at the moment. You can instead create a container executor with a Python image and basic modules that Testkube will use to execute Pytest tests on Kubernetes. 

Both test executors and container executors allow you to run specific and custom test types in Testkube. Container executors were helpful when you wanted to run your custom tests. However, it wasn’t very user-friendly. Users had to do a lot of manual configurations that were tedious and error-prone for more advanced testing needs, so a better way was needed.

Test Workflows

Building on the learnings from container executors, Test Workflows provide a comprehensive, purpose-built solution for managing the full lifecycle of running tests against your applications and their components. This includes everything from provisioning necessary infrastructure components to running tests in parallel to maximize throughput, integrating seamlessly with other testing tools, and orchestrating complex tests. 

Test Workflows use Kubernetes-native capabilities to run all the components specified in a test workflow, from executing tests to collecting logs and results in real-time and showing them on the Testkube dashboard. 

Test Workflows are single yaml files that comprise everything required to define a test workflow. And just like tests and executors, Test Workflows are stored as custom resources in your cluster, making them easy to manage using existing Kubernetes tools and GitOps pipelines. 

Test Workflows comes with a powerful templating engine that allows you to define common testing configurations which ensure standardization and consistency across your testing efforts. You can use any of our existing templates or create your own templates as needed.

Benefits of Test Workflows

Test Workflows unlock numerous advantages for improving the efficiency of your testing efforts. Some of these benefits include:

  • Resource Allocation: Test Workflows allow you to easily and precisely define your resource requirements for testing upfront from CPU to memory requirements. This allows your tests to execute uninterrupted and scale based on requirements. 
  • Single Specification: The test workflow is a single specification where you define your tests, containers, resource requirements, variables, and everything else. Since this is a single place to define all your requirements, it becomes easy to manage. 
  • Templating: With Test Workflows, you can create reusable templates that help you achieve standardization. These templates are less prone to errors and ensure consistent test execution across the board. 

Read more about Test Workflows to see how they empower developers to deliver high-quality software faster by centralizing and streamlining the testing process.

Test Workflows in Action

Now that we’ve understood Test Workflows and their benefits, let's see them in action and understand how they work. In this short demo, we’ll walk through the process of creating a test workflow to execute a test and also examine how it streamlines the complete testing lifecycle.

We will use the default k6 test workflow template for this hands-on demo.

Pre-requisites

  • A Testkube Pro account (free plan is fine)
  • Kubernetes cluster - we’re using a local Minikube cluster.
  • Testkube Agent configured on the cluster.

Once the prerequisites are in place, you should have a target Kubernetes cluster ready with a Testkube agent configured. 

Creating a Test Workflow

Navigate to the Test Workflows tab and click on “Add a new test workflow”

This will provide you with two options:

  • Use a working example - use existing k6, cypress, and playwright examples
  • Import from yaml - import your own test workflow

We’ll use a working example, but you can implement your own workflow as well. For more information, refer to our guide on creating test workflow templates

Choose “Use a working example”

On the next tab, choose “k6 load test” and provide a name for your workflow. The spec section contains detailed specifications for your test workflow. Below is the default spec file for k6te

```yaml

kind: TestWorkflow
apiVersion: testworkflows.testkube.io/v1
metadata:
 name: k6-workflow
 namespace: testkube
spec:
 content:
   git:
     uri: https://github.com/kubeshop/testkube
     revision: main
     paths:
     - test/k6/executor-tests/k6-smoke-test.js
 container:
   workingDir: /data/repo/test/k6/executor-tests
   resources:
     requests:
       cpu: 128m
       memory: 128Mi
 steps:
 - name: Run test
   run:
     env:
     - name: K6_SYSTEM_ENV
       value: K6_SYSTEM_ENV_value
     - name: K6_WEB_DASHBOARD
       value: "true"
     - name: K6_WEB_DASHBOARD_EXPORT
       value: /data/artifacts/k6-test-report.html
     args:
     - run
     - k6-smoke-test.js
     - -e
     - K6_ENV_FROM_PARAM=K6_ENV_FROM_PARAM_value
   container:
     image: grafana/k6:0.49.0
   artifacts:
     workingDir: /data/artifacts
     paths:
     - '*'
   setup:
   - shell: mkdir /data/artifacts

```

The spec file includes the following components:

  • Content: contains the details of your test
  • Container: defines the image for your test executor, including CPU and memory requirements
  • Steps: defines the steps for the test to follow along with the arguments, artifacts and initial setup

You can change the parameters here based on your requirements, but we will not do that now. 

Read our test workflow document to understand more about the test workflow specification. 

Click on “Create” to create the test workflow.

Once the workflow is ready, you’ll see the newly created test workflow on the screen. Click on it and click “Run Now” to start the workflow.

You’ll see the workflow executing along with the real-time logs of every step. 

After the execution, Testkube also collects all the artifacts, in this case, a k6-report where you can view all the results and outputs.

This was a straightforward demo of using Test workflows for Kubernetes testing. You can create custom workflows and import them to Testkube to take greater advantage of test workflows. 

What’s next for Test Workflows?

Apart from Workflows currently being integrated into the Testkube architecture to make it compatible with Test Triggers, Test Suites, Status Pages, etc., we are adding a number of powerful features not available for Tests and custom Executors:

  • Test Insights - provides detailed status/execution metrics for your Test Workflows, helping you answer both strategic and tactical questions about your ongoing testing efforts, likesome text
    • Which workflows take the most execution time?
    • What’s the pass/fail ratio of a specific workflow or its contained tests over time?
    • How many workflows with a specific label are we running?
    • and much more.
  • Test Parallelisation - powerful parallel execution of tests to enablesome text
    • Massive load generation with tools like k6, JMeter, Artillery, and Gatling 
    • Optimized test execution times by distributing tests across multiple executions for different tests, input parameters/browsers/etc. for tools like Cypress and Playwright.
    • Using your own infrastructure for both of these instead of depending on 3rd party solutions.

Summary

Test workflows are the next evolution in testing for Kubernetes. By bringing the entire testing lifecycle into a single, declarative workflow, Test Workflows empower teams to scale, simplify, and standardize their testing workflows. 

The benefits of adopting Test Workflows are clear, too - improve scalability consistency through templating and single spec files for easier management - to name a few. 

We invite you to try Test Workflows. Visit Testkube website to get started. If you find yourself struggling with anything, feel free to drop a note in our active Slack community, and someone will help you out.

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 for free.