Chinni
Chinni

Reputation: 804

How to Generate the Unique Dynamic First Name, Last Name for each Test in JMETER

Here is the situation due to our application complexity and so many Integration env's, we can not delete the Injected Data(through the performance test) before Next test or to repeat the Tests.

Every Time we need to run test about an hour with 10,000 Unique Employee (First Name, Last Name) Note : First Name & Last Name should be purely alphabetic. Ex: FName: Edward Last Name:Jerick

How do I achieve the above

Upvotes: 0

Views: 393

Answers (1)

Dmitri T
Dmitri T

Reputation: 168217

First of all it sounds like a functional defect, the system should allow duplicate first and last names combination, I don't know how many John Smiths are in the USA but I suppose that the number is much more than 1.

Whatever.

You can pre-generate the list of 10000 unique first and last names (or at least alphabetic strings) in setUp Thread Group using JSR223 Sampler and the code like:

Set<String> firstNames = new HashSet<>()
Set<String> lastNames = new HashSet<>()

0.upto(9999, {
    firstNames.add(org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(16))
})

0.upto(9999, {
    lastNames.add(org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(16))
})

0.upto(9999, {
    new File('credentials.csv') << firstNames[it] << ',' << lastNames[it] << System.getProperty('line.separator')
})

If you want "real" names instead of random you can check out Java Faker library

Then you can refer the generated data from the credentials.csv file in the "normal" Thread Group using CSV Data Set Config

Upvotes: 0

Related Questions