run a test from IDE using App trait

Hi Guys,

I updated my project to use 2.1.0-SNAPSHOT version because I needed the latest websocket bug fix. Apart from some scala 2.11.4 issues and gatling api changes everything is ok now. I can run my test using sbt gatling:test.
But in the stable version I could use something like this to start the test from intellij:

object CometDGatlingTest extends App {
val gatlingPropertyBuilder = new GatlingPropertiesBuilder
gatlingPropertyBuilder.simulationClass(classOf[CometDGatlingTest].getName)
Gatling.fromMap(gatlingPropertyBuilder.build)
}

class CometDGatlingTest extends Simulation with Logging {

}

In the new snapshot version I cannot do this as the api has changed.
What is the best practice now to start a test programmatically with a specific test class?

Thx,
Krisztian

Hi Krisztian,

This method was removed a bit too fast. We were aware of it and planning to bring in back today, we just didn’t expect someone to be impacted so fast.
https://github.com/gatling/gatling/commit/204237dda052d7f907049a895b65f03c7575bbda

We’re re-introducing it temporarily to ease maven archetype based projects, but it will be definitively dropped in 2.2.
See deprecation message for migration.

Cheers,
Stéphane

Hi,

Is it possible that something else has been changed as well?

Exception in thread “main” java.nio.file.NoSuchFileException: ./target/test-classes
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
at sun.nio.fs.UnixFileSystemProvider.newDirectoryStream(UnixFileSystemProvider.java:426)
at java.nio.file.Files.newDirectoryStream(Files.java:413)

I believe that not just the fromMap method changed which is responsible for being able to run the test like an App.
I saw the same exception when I wanted to use the following:
new Gatling(props.build, simulationClass).start

But it was OK in the stable version.

Thx,
Krisztian

Hi,

This change comes from the refactoring I made to allow Gatling to upgrade to Scala 2.11.
Gatling search the compiled classes in target/test-classes by default, but in your case, even if this folder does exist, the path is incorrect.
You can, if you want, have a look at how the Maven Archetype fixes this :

https://github.com/gatling/gatling-maven/blob/master/gatling-highcharts-maven-archetype/src/main/resources/archetype-resources/src/test/scala/IDEPathHelper.scala
https://github.com/gatling/gatling-maven/blob/master/gatling-highcharts-maven-archetype/src/main/resources/archetype-resources/src/test/scala/Engine.scala

But it’ll be faster to simply copy those classes from the archetype into your project and run the Engine class :wink:

Side note :
Since you’re using 2.1 snapshots, you may like the fact that the mute mode (not asking for simulationID nor run description) works everywhere, and not only for the SBT plugin.
If you activate it (gatlingPropertyBuilder.mute()), your simulation would now run right away, without asking for inputs. In short, faster development cycles for free :slight_smile:

Cheers,

Pierre

Hi Pierre,

I remembered that there was an Engine and a IDEPathHelper long time ago and I used to use them from gatling 1.5. But since I updated to gatling 2 I couldn’t find them.
Thanks the update.

Cheers,
Krisztian

It has always been there :wink:
But when we migrated Gatling from Maven to SBT, the projects necessarily relying on Maven (e.g. our Maven plugin and archetype) were moved to their own repositories, and unified in 2.1 in single gatling-maven repository.

Thx the help anyway.

@Stephane you can remove the fromMap method as it is not used.

k

I realized a bit too late that removing ‘fromMap’ was a really bad idea…
On master, there is now ‘fromMap’ and ‘fromArgs’ to start Gatling, and the older ‘runGatling’ is now deprecated.