Nowadays, ensuring the performance and reliability of your applications is crucial. Load testing helps identify performance bottlenecks and ensures your application can handle expected traffic. One popular tool for load testing is k6, which is known for its simplicity, robustness, and seamless integration with CI/CD pipelines.
In this article you will see how to integrate k6 load tests with three major CI/CD platforms: Azure DevOps, GitHub Actions, and GitLab CI.
Prerequisite - create a basic k6 test script
In each of the following CI/CD integration examples I will be using a simple script.js file that looks like this
Integrating k6 with GitHub Actions
- Create a new repository that contains the above script.js file
- In the project root, create the following “.github/workflows/loadtest.yml” file (notes: ‘.github’ and ‘workflows’ are folders and ‘loadtest’ is just a random file name, it can be anything)
The loadtest.yml looks like this
3. Triggers: From now on, each and every git push (including pushing this file) will trigger the workflow and execute the k6 tests – you can see the pipelines in the GitHub repository, “Actions” area
Integrating k6 with GitLab CI
- Create a new repository that contains the above script.js file
- In the project root, create the following “.gitlab-ci.yml” file that will look like this
3. Triggers: From now on, each and every git push (including pushing this file) will trigger the workflow and execute the k6 tests – you can see the pipelines in the GitLab repository, left side menu Build > Pipelines
Integrating k6 with Azure DevOps
- Create a new repository that contains the above script.js file
- Important note: before going further, you have to install k6 plugin for AzureDevOps by accessing THIS LINK
- In the project root, create the following “azure-pipelines.yml” file that looks like this
3. Triggers: From now on, each and every git push (including pushing this file) will trigger the workflow and execute the k6 tests – you can see the pipelines in the AzureDevops repository, left side menu “Pipelines > Pipelines”
Conclusion
Integrating k6 load testing into your CI/CD pipelines ensures that performance testing is part of your development lifecycle, catching issues early and improving the reliability of your applications.
By following the steps outlined above, you can set up automated k6 load testing in your CI/CD pipelines, gaining insights into application performance with every code change.
Enjoyed this article? Make sure to subscribe to my YouTube Channel for more Test Automation tutorials, and follow me on LinkedIn and Twitter for regular insights.
Looking to improve your test automation skills?
I’ve created a personalized 1-on-1 Mentoring program refined to boost YOUR skills. Reach out at iamrv@razvanvancea.ro for more details and together will create a learning path adapted to your current skills and goals that you are aiming for, in a timely-efficient manner🚀