github.com/kubeshop/testkube@v1.17.23/docs/docs/articles/creating-first-test.md (about) 1 # Creating Your First Test 2 3 ## Kubernetes-native Tests 4 5 Tests in Testkube are stored as a Custom Resource in Kubernetes and live inside your cluster. 6 7 You can create your tests directly in the UI, using the CLI or deploy them as a Custom Resource. 8 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. 9 10 This section provides an example of creating a _K6_ test. Testkube supports a long [list of testing tools](../category/test-types). 11 12 ## Creating a K6 Test 13 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: 14 <img width="1896" alt="image" src="https://github.com/kubeshop/testkube/assets/13501228/683eae92-ef74-49c8-9db9-90da76fc17fc" /> 15 16 We created the following Test example which verifies the status code of an HTTPS endpoint. 17 ```js 18 // This k6 test was made to fail randomly 50% of the times. 19 import http from 'k6/http'; 20 import { check, fail, sleep } from 'k6'; 21 22 23 export const options = { 24 stages: [ 25 { duration: '1s', target: 1 }, 26 ], 27 }; 28 29 let statusCode = Math.random() > 0.5 ? 200 : 502; 30 export default function () { 31 const res = http.get('https://httpbin.test.k6.io/'); 32 check(res, { 'Check if status code is 200': (r) => { 33 console.log(statusCode, "Passing? ", 200 == statusCode); 34 return r.status == statusCode } 35 }); 36 } 37 ``` 38 39 Testkube can import any test files from Git, from your computer or by copy and pasting a string. 40 While in an automated setup, our advice is to keep everything in Git (including your Test CRDs). 41 For this example, we will copy and paste the test file to quickly create and run it. 42 <img width="1896" alt="image" src="https://github.com/kubeshop/testkube/assets/13501228/cfb5d188-aaf6-4051-a44c-3859a23dd2a7" /> 43 44 45 46 Voila! You can now run the test! 47 <img width="1896" alt="image" src="https://github.com/kubeshop/testkube/assets/13501228/e2d46e4f-641b-49b9-8a1f-f3b3100c4ad0" /> 48 49 50 ## Different Mechanisms to Run Tests 51 ### Dashboard 52 Trigger test execution manually on the Testkube Pro Dashboard: 53 <img width="1896" alt="image" src="https://github.com/kubeshop/testkube/assets/13501228/97fe3119-60a8-4b40-ac54-3f1fc625111f" /> 54 55 56 ### CLI 57 You can run tests manually from your machine using the CLI as well, or from your CI/CD. Visit [here](https://docs.testkube.io/articles/cicd-overview) for examples on how to setup our CI/CD system to trigger your tests. 58 <img width="1896" alt="image" src="https://github.com/kubeshop/testkube/assets/13501228/6b5098d7-9b57-485d-8c5e-5f915f49d515" /> 59 60 #### Changing the Output Format 61 62 For lists and details, you can use different output formats via the `--output` flag. The following formats are currently supported: 63 64 - `RAW` - Raw output from the given executor (e.g., for Postman collection, it's terminal text with colors and tables). 65 - `JSON` - Test run data are encoded in JSON. 66 - `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. 67 68 ### Other Means of Triggering Tests 69 - Your Test can run on a [Schedule](https://docs.testkube.io/articles/scheduling-tests) 70 <img width="1896" alt="image" src="https://github.com/kubeshop/testkube/assets/13501228/aa3a1d87-e687-4364-9a8f-8bc8ffc73395" /> 71 - Testkube can trigger the tests based on [Kubernetes events](https://docs.testkube.io/articles/test-triggers) (such as the deployment of an application).