Skip to main content
New to Testkube? Unleash the power of cloud native testing in Kubernetes with Testkube. Get Started >

Creating Your First Test

warning

Features described in this document are being deprecated as part of the transition to Test Workflows - Read More.

Kubernetes-native Tests

Tests in Testkube are stored as a Custom Resource in Kubernetes and live inside your cluster.

You can create your tests directly in the UI, using the CLI or deploy them as a Custom Resource. Upload your test files to Testkube or provide your Git credentials so that Testkube can fetch them automatically from your Git Repo every time there's a new test execution.

This section provides an example of creating a K6 test.

Creating a K6 Test

Now that you have your Testkube Environment up and running, the quickest way to add a new test is by clicking "Add New Test" on the Dashboard and select your test type:

image

We created the following Test example which verifies the status code of an HTTPS endpoint.

// This k6 test was made to fail randomly 50% of the times.
import http from "k6/http";
import { check, fail, sleep } from "k6";

export const options = {
stages: [{ duration: "1s", target: 1 }],
};

let statusCode = Math.random() > 0.5 ? 200 : 502;
export default function () {
const res = http.get("https://httpbin.test.k6.io/");
check(res, {
"Check if status code is 200": (r) => {
console.log(statusCode, "Passing? ", 200 == statusCode);
return r.status == statusCode;
},
});
}

Testkube can import any test files from Git, from your computer or by copy and pasting a string. While in an automated setup, our advice is to keep everything in Git (including your Test CRDs). For this example, we will copy and paste the test file to quickly create and run it.

image

Voila! You can now run the test!

image

Different Mechanisms to Run Tests

Dashboard

Trigger test execution manually on the Testkube Pro Dashboard:

image

CLI

You can run tests manually from your machine using the CLI as well, or from your CI/CD. Visit here for examples on how to setup our CI/CD system to trigger your tests.

image

Changing the Output Format

For lists and details, you can use different output formats via the --output flag. The following formats are currently supported:

  • RAW - Raw output from the given executor (e.g., for Postman collection, it's terminal text with colors and tables).
  • JSON - Test run data are encoded in JSON.
  • GO - For go-template formatting (like in Docker and Kubernetes), you'll need to add the --go-template flag with a custom format. The default is {{ . | printf("%+v") }}. This will help you check available fields.

Other Means of Triggering Tests

  • Your Test can run on a Schedule image
  • Testkube can trigger the tests based on Kubernetes events (such as the deployment of an application).