Hi.
I’m new to k6, and trying to find some best practices.
I want to create a load test that mixes a lot of different types of scenarios, so we can run a somewhat realistic load on the website.
I’m thinking this means that we should use the Scenarios feature to be able to run all these tests in parallel.
But I think it gets quite messy if we add 50 or 100 scenarios in one big file. What is the correct way to put each test/scenario in its own file?
At the same time, we probably want to have one list of users credentials that all the scenarios can read from, so we probably only want to do one SharedArray so each test does not have to read the same data? How would that work with splitting the tests into files?
Are there any examples out there of large test projects?
Thank you in advance
Hi @mortenbock,
Welcome to the k6 community!
You might want to take a look at this answer for splitting scenarios into multiple files: Can we import js files in another k6 js file with scenarios in it?.
You can also store the credentials in another file with this approach. Or, yes, you can use the following approach for sharing the credentials: Data Parameterization. Also, please take a look at this answer.
Thanks!
Thank you.
If using the method where the scenario references a referenced file, is it possible to use the same SharedArray of data across the referenced files? I cannot see a way to pass that data as a parameter for example.
Would each test file need to create it’s own instance of the SharedArray?
SharedArray
returns you a JavaScript Array
for sharing data between multiple VUs. So, in theory, you should be able to pass it as a variable to other files after you build it once in the main test code. Or, you can have code to call in the init
function to init other files’ shared arrays. I haven’t tried it myself, but these approaches seem they might work.