Test Workflows
Introduction
Test Workflows are an easy and extremely powerful way to define and run your tests in your Kubernetes clusters. Thanks to their flexibility, Test Workflows solve many of the problems that can occur with standard Tests, including:
- Running Tests using different testing tool versions and dependencies.
- Defining multiple steps for the execution of the tests.
- Having more control over how your tests are executed, including resource consumption and setup/tearDown processes.
- Being able to configure tool-specific commands and arguments.
Most of the test execution functionality provided by the Test Workflows engine is available for free using the Open Source Testkube Agent in Standalone Mode - Read More.
Test Workflow Structure Overview
Test Workflows are defined via a Kubernetes Custom Resource Definition (CRD) that uses a custom workflow language. Below is a high-level outline of a Test Workflow definition:
apiVersion: testworkflows.testkube.io/v1
kind: TestWorkflow
metadata:
name: ... # Name of the Test Workflow
spec:
content: # Where to find the test definitions
git: # Checkout from a Git repository
...
files: # Inline file definitions
...
container: # Global container settings (can be overridden)
resources: # Resource requests and limits
requests: ...
limits: ...
workingDir: # Default working directory
env: # Global environment variables
...
execution: # Optional execution properties
tags: # execution tags
...
target: # target specific Runners
...
steps: # Ordered steps for execution (supports nesting)
- name: ... # name of step
run:
image: ...
command: [...]
args: [...]
The different properties are described with examples and in more detail below.
The Schema Reference for Test Workflows describes all available properties and constructs
Metadata
The metadata section follows standard Kubernetes convention.
Name
metadata.name
: (Required) The name of the Test Workflow (e.g.example-workflow
).
Labels
metadata.labels
: (Optional) Labels help with filtering and organizing workflows.
metadata:
name: example-workflow
labels:
example: label
another: one
one: more
Content Sources
The content section specifies the test scripts or files to run.
Git Repositories
You can check out tests from a Git repository:
spec:
content:
git:
uri: https://github.com/kubeshop/testkube
revision: main
paths:
- test/cypress/executor-tests/cypress-13
Files
Alternatively, you can define test files directly:
spec:
content:
files:
- path: k6.js # File created in the working directory
content: |
import http from 'k6/http';
export const options = {
thresholds: { http_req_failed: ['rate<0.01'] },
};
export default function () {
http.get('https://testkube.io/');
}
- path: /example-file.js # File created in the root directory
content: Another file content
Container Configuration
The container section sets up the environment where steps run. These settings can be applied globally or overridden on a per-step basis.