Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run gatling from code

I would like to run Gatling test from code. How to do it? Tutorials says only about command line and sbt.

Context: I would like to extend tests. In background I have custom socket communication which I need to simulate. From that simulation I need to pass some generated Ids to Gatling test. I could do it by running it from my simulation app with parameters (but I don't know yet how). Other solution would be also a good answer.

I could do some passing through file and http://gatling.io/docs/2.1.6/cookbook/passing_parameters.html , but it is ugly..

Maybe there is way to run sbt task from scala code?

like image 372
Waldemar Wosiński Avatar asked Jun 26 '15 07:06

Waldemar Wosiński


People also ask

How do I run a Gatling script in Intellij?

If you want to run gatling tests inside the intellij, you can go to the edit configurations in the run toolbar on the top left and add a new sbt task. On the task field enter testOnly simulations:BasicSimulation and that's it.

How do you make a Gatling project?

Gatling Maven project can be created by directly importing the required Maven dependencies in a Maven project pom. xml file, or we can create the project using Maven archetype for Gatling which comes with all the setup and libraries that are required to get started with a Maven-based Gatling project.


2 Answers

import io.gatling.app.Gatling
import io.gatling.core.config.GatlingPropertiesBuilder

object Engine extends App {

  val props = new GatlingPropertiesBuilder
  props.simulationClass("your.simulation.class.goes.here")
  props.dataDirectory("path.to.data.directory") //optional
  props.resultsDirectory("path.to.results.directory") //optional
  props.bodiesDirectory("path.to.template.directory") //optional
  props.binariesDirectory("path.to.binaries.directory") //optional

  Gatling.fromMap(props.build)
}

Hope this will help.

like image 110
vkadam Avatar answered Nov 25 '22 09:11

vkadam


I agree that the documentation on the Gatling website doesn't explain that well (I looked for it the other day) however Gatling has provided an excellent sample with some documentation on how to achieve this:

https://github.com/gatling/gatling-sbt-plugin-demo

like image 26
bjfletcher Avatar answered Nov 25 '22 10:11

bjfletcher