Wednesday, February 12, 2014

Random (II)

Randomness is important for performance testing because realistic users behave randomly to some degree, we need to have some randomness to better emulate the real users. In one of earlier blogs, we covered some randomness related functions, here we show a more complete list.

randNumber(<minNum>, <maxNum>, ["float"])

This function is the most commonly used function, it will give a random number between min and max. The third parameter is optional, if it's omitted, it will return an integer. Here is a simple but interesting example: randomly pick a product from a web page and view it

This function is what makes it so easy to pick an item from a set of web page. As an example, suppose you want to emulate a virtual user who clicks a link in the navigation region of a web page, the following code snippet will suffice:

If you have used some other test platform(s), you may remember how hard it is to do something this simple -- you may have to write a long script ladened with API calls.

randSequence(<min>, <max>)

This function will return a subset of numbers between min and max. For example, randSequence(1,10) returns a sub sequence of 1,2,3,...8,9,10. Here is where it can be useful: suppose a web page contains n items, you want to emulate user who is going to click a random sub sequence of 1,2,3, ...n.

This function is the latest in this series, it's more general than the previous function (randSequence) in that the input may not be a sequence of consecutive numbers. It treats the input array as a set and return a subset of it. Here is the test scenario where it can be quite handy: on a social media site, user can look for interests news on a subset of people (the celebrities), using this function, it was easy to emulate such a user behavior.