Testkube: The Kubernetes-native testing framework
Tags: kubernetes, devops, testing, opensource
Published: 2022-09-29 16:01:39

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3swjf6g0ncdexrran5gb.png)

## CI/CD Workflow Without TestKube

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hjdyhob1fcab1hg3mr89.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e4gphzsqfimozjf84lr1.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n76er5kses0izmjjcdw8.png)

## 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
```

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);
}

```
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
```

- Now, run this command.

```
$ kubectl testkube run test k6-test -f

```
Now, we can view our logs and test results in the Testkube dashboard. Run this command.👇

```
$ kubectl testkube dashboard

```

## Thank You
I hope you learn something from this blog.