Introduction
Continuous testing in CI is extremely important in product development.
Load testing is no exception to this rule, and we want to avoid situations where we run a load script after a long time only to find that it doesn’t work at all.
In this article, we’ll implement continuous automated testing by running k6 load scripts against a mock API server in CI.
This article assumes that you have already set up a mock API server as described in the following article.
Please refer to it as needed.
https://gonkunblog.com/k6-prepare-mock-server/1934/
Implementation Goal
We’ll define a GitHub Actions CI named mockTestForSampleApp
that will run automatically, as seen in this PR.
If you just want to see the conclusion, please refer to the following PR:
https://github.com/gonkunkun/k6-template/pull/3
Setting Up CI
Prerequisites
The explanation is based on the following sample repository:
https://github.com/gonkunkun/k6-template
The components in the CI environment are as follows:
k6
- We’re using xk6 to handle extensions
- The execution command is generated by building with Go
Redis
- Used to store user data
- Detailed in the following article
- https://gonkunblog.com/k6-how-to-get-options-settings/1914/
Mock API Server
- Instead of calling the actual API server from k6, we call a mock API server
Setup
Prepare an env file for CI (.env.ci
):
Create .github/workflows/mockTest.yml
:
After setting up the environment, we finally run the smoke test scenario:
Now just create a normal PR and verify that the CI works.
Looking at the CI execution logs, we can confirm that k6 is running successfully.
Note that there are some parts where caching isn’t working properly.
Please forgive this as a future challenge.
Conclusion
With CI, we can now verify that k6 scenarios aren’t broken every time.
The repository used in this article is explained in the following article.
If you’re interested, please check it out.
https://gonkunblog.com/k6-project-template/1846/
How much test code should be written for load testing scripts is debatable.
In this example, we can confirm that k6 executes and the scenario runs completely, but we cannot guarantee the behavior of modules and APIs called within the scenario.
If anyone knows a good way to handle this, please contact me quietly…
Thank you for reading this far.