Test data is the information designed to be used by test script during execution. Using different values for certain parameters will make the test more realistic.
Common use cases for test data might be usernames and passwords, emails, addresses, names, personal information, prodct names and so on.
In this article we will explore 4 ways of handling this subject. It worths mentioning that the SharedArray approach will be the most efficient method.
1) Arrays - simplest way to add test data
2) CSV file
In this approach we are going to keep the data sets (pairs of usernames+passwords) into a CSV file, import it in our k6 script then use a random variable that randomly picks data
3) JSON file
In this approach we are going to keep the data sets (pairs of usernames+passwords) into a JSON file, import it in our k6 script then use a random variable that randomly picks data
4) SharedArray - the most efficient approach
The shared array approach must be combined with any of the previous approaches and it is the most efficient way to add data within a k6 test because it handles the high resource utilization most efficiently.
The reason is that in the previous approaches when a file is used in a test, multiple copies of the files are created and sent to the load generator; when the file is large it can have an impact on the resources. Hence, to prevent this, the SharedArray approach should be the go-to option.
In the following example, I will be using SharedArray combined with the JSON approach.
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🚀