Using javafaker or other class to generate values

615 views
Skip to first unread message

Jason Harmon

unread,
Sep 29, 2015, 5:52:36 PM9/29/15
to Gatling User Group
I'm attempting to use java Faker () to generate some test data (rather than storing big CSV files). As it stands now, I get the same value for all test iterations (I have some .repeat steps in my scenario).

Example:
import com.github.javafaker.Faker
 
class TestSimulation extends Simulation {

val faker = new Faker()
<snip>
 
faker.name().fullName() // passed into some request body

It seems like this should be a ThreadLocal (or DynamicValue), but I'm not Scala savvy enough to get it working. 

Thanks

adrian...@hushmail.com

unread,
Sep 30, 2015, 5:27:09 AM9/30/15
to gat...@googlegroups.com
Try using an anonymous function, something like ...

 exec(_.set("fullName", "${faker.name.fullName}"))

 ...

 .formParam("fullName", "${fullName}") 

Aidy

--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jason Harmon

unread,
Sep 30, 2015, 2:43:25 PM9/30/15
to Gatling User Group
So I came up with an idea to fake a feeder/iterator:

  class FakeStreetAddress extends Feeder[String] {
   
override def next(): Map[String, String] = {
     
Map("street_address" -> faker.address().zipCode)
   
}

   
override def hasNext: Boolean = true
 
}

Then I can set .feed(new FakeStreetAddress).

This works, but is really quite verbose to create a feed for each field I'd like to fake.

I tried your suggestion (frankly not totally understanding what "_.set()" does), and got this error:

missing parameter type for expanded function ((x$1) => x$1.set("full_name", "${faker.name().fullName()}"))
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+unsubscribe@googlegroups.com.

Jason Harmon

unread,
Sep 30, 2015, 2:45:42 PM9/30/15
to Gatling User Group
Oops typo, make that:

  class FakeStreetAddress extends Feeder[String] {
   
override def next(): Map[String, String] = {

     
Map("street_address" -> faker.address().streetAddress(true))

Pierre DAL-PRA

unread,
Sep 30, 2015, 3:12:56 PM9/30/15
to gat...@googlegroups.com
Hi,

Have a look at the documentation, you'll see that we provide an example for EXACTLY what you're trying to do : http://gatling.io/docs/2.1.7/session/feeder.html#feeders .

Cheers,

Pierre

Oops typo, make that:

To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.

Jason Harmon

unread,
Sep 30, 2015, 3:24:39 PM9/30/15
to Gatling User Group
Duh RTFM missed that first paragraph in the feeders section.

For posterity:

val fakeData = Iterator.continually(
   
Map("full_name" -> faker.name.fullName,
       
"street_address" -> faker.address.streetAddress(true),
       
"zip_code" -> faker.address.zipCode,
       
"state" -> faker.address.stateAbbr,
       
"city" -> String.format("%s%s", faker.address.cityPrefix, faker.address.citySuffix)
   
)
 
)
 
<snip>
 
.feed(fakeData)
 
<snip>
 
.body( StringBody( """{ "street_address": "${street_address}", }""" ) )

Thanks!
Oops typo, make that:

To unsubscribe from this group and stop receiving emails from it, send an email to gatling+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages