Test Workflow Templates
Test Workflow Templates allow you to define building blocks which you can reuse across your Workflows. Strategically, templates can bring standardization across your organization. You can define a tool chain which is easy to discover across teams. At a more tactical level, templates avoid repetition and can be used to hide implementation details.
Templates are flexible and can be used is various ways:
- Template testing tools: Define a common usage of Cypress (or any other tool) across your organization.
- Template setup: Run scripts before your tests or tear down steps.
- Template test sources: Define credentials once to make it easy to update them.
- Template common labels: Attach labels per company department.
- Template technical details: Define an abstraction which handles closing Istio sidecar.
- Template integrations: Run anything after tests fail.
- Template resource constraints: Define common container resource limits for all your tests.
- Template log collection: Collect logs from tested components to help with troubleshooting read more.
- Template application-under-test: Start the actual components to be tested (and/or their dependencies) instead of relying those to be running.
Basics
Create a Template
You can manage your templates under Workflows > Workflow Templates within the Dashboard (Read More) or create a TestWorkflowTemplate Custom Resource in your Kubernetes cluster using the Testkube CLI. This custom resources follows the same structure as a Test Workflow, with the additional ability to define configuration parameters that can be specified when the template is used.
To learn how to create and publish your own custom templates that appear in the Dashboard wizard, see Creating your own Workflow Templates.
The example below templates a testing tool. More specifically, it defines a k6 test with parameters for the k6 version to use and the parameters to pass to k6.
kind: TestWorkflowTemplate
apiVersion: testworkflows.testkube.io/v1
metadata:
name: example-template--k6
spec:
config:
version:
description: k6 version to use
type: string
default: 0.49.0
params:
description: Additional params for the k6 run command
type: string
default: ""
steps:
- name: Run k6 tests
container:
image: grafana/k6:{{ config.version }}
shell: k6 run {{ config.params }}
Or another example would be to set resources:
apiVersion: testworkflows.testkube.io/v1
kind: TestWorkflowTemplate
metadata:
name: run-size-lg
spec:
container:
resources:
requests:
cpu: 2
mem: 1Gb
limits:
cpu: 3
mem: 2Gb
Using a Template
Your workflows can use one or multiple templates. You can use a template within the workflow as a whole or within a step. When you run a workflow with templates, then our workflow engine will first inline the templates before executing. To learn how templates are inlined, you can see this advanced section.