DEV Community

Cover image for Testkube: The Kubernetes-native testing framework
Aditya simant
Aditya simant

Posted on

Testkube: The Kubernetes-native testing framework

What is TestKube?

Testkube is a Kubernetes-native testing framework. It enables running tests directly in your Kubernetes cluster and then saves the results to a centralized space. It abstracts away all the troubles of containerizing different test types. Testkube makes testing in Kubernetes a smooth cloud-native experience.

TestKube gives us a centralized test result and is simple to integrate with GitOps and CI/CD procedures.

So, in this blog, we will go to cover:

  • Why Testkube?
  • Is it for you?
  • Installation of Testkube
  • Demo.

Prerequisties:

  • Basic knowledge of K8s

Why TestKube?

TestKube Decouples the testing activities performed at CI/CD pipeline and defines them in Testkube so that we can run our tests anytime without having to run the entire CI/CD pipeline for running an individual test, So moving across CI/CD platforms becomes more accessible as we don't need to redefine all the tests as we can reuse the way tests has been defined and orchestrated in TestKube.

CI/CD Workflow With TestKube

Image description

CI/CD Workflow Without TestKube

Image description

Because TestKube retrieves the test files from the project repository and executes them as you want, you don't need to perform any complicated settings to run your tests.

The complexities involved with CI/CD testing are simplified as TestKube Manages all the testing activities themselves.

TestKube provides the entire infrastructure for taking care of all testing workloads from inside the Kubernetes cluster.

Is TestKube for you?

  • If you are doing Integration testing for your application under Kubernetes, Testkube is for you.
  • If you wish to surpass K8's limitations, such as network limits or lack of access to testing environments
  • If your CI/CD and testing processes are too closely related

Installation

  • Now, open your terminal and write this command.πŸ‘‡
    $ kubectl testkube install

  • Now, run thisπŸ‘‡ command to view all the TestKube components.
    $ kubectl get pods -n testkube

Now, your screen will look like thisπŸ‘‡

Image description

Now, we will be able to see both client and server versions.

  • To see the version of the TestKube, run this command.πŸ‘‡ $ kubectl testkube version

To run your test, run this command.πŸ‘‡
kubectl testkube run test our-first-test-name

The screen will look like this.πŸ‘‡

Image description

Running a K6 Test

K6 is integral part of Testkube. During the Testkube installation, the Testkube k6 executor installs by default. You must first build a Test in Testkube to perform a K6 test.

  • Create a new JS file.
// bash

$ touch k6-test.js

// You can give any name
Enter fullscreen mode Exit fullscreen mode

Now we will create a k6 load test and run it. Write this code πŸ‘‡ inside the k6-test.js file.

import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
stages: [
 { duration: '5s', target: 20 },
 { duration: '5s', target: 10 },
],
};
export default function () {
const res = http.get('https://httpbin.test.k6.io/');
check(res, { 'status was 200': (r) => r.status == 200 });
sleep(2);
}

Enter fullscreen mode Exit fullscreen mode

Save the file as k6-test.js or anything you like.

  • Now execute the test script. First, we need to define it as k6/script πŸ‘‡

$ kubectl testkube create test --file path/to/your/k6-test.js --type "k6/script" --name k6-test
Enter fullscreen mode Exit fullscreen mode
  • Now, run this command.
$ kubectl testkube run test k6-test -f

Enter fullscreen mode Exit fullscreen mode

Now, we can view our logs and test results in the Testkube dashboard. Run this command.πŸ‘‡

$ kubectl testkube dashboard

Enter fullscreen mode Exit fullscreen mode

Thank You

I hope you learn something from this blog.

Top comments (2)

Collapse
 
harshal_rajnoor profile image
Harshal_rajnor

Awesome. Expecting more such blogs.

Collapse
 
adityasimant profile image
Aditya simant

sure