I’d like to write some tests for testing my core libraries that my gatling scripts are founded upon. Especially since now I’m porting them to run under sbt.
What have you done for creating unit tests of your library code in the past? And can I add a task to my build to run all of them?
Hey John –
Here’s how I structure my simulations in set projects:
- I use the main, test and integration set configurations (http://www.scala-sbt.org/0.13/docs/Testing.html)
– All code that I run with the bundle (i.e., simulations and helpers) goes into src/main, which is what I provide as argument for the -sf option
– Unit tests that run outside of gatling are in src/test; for example, I have several custom feeders that I test that way
– I treat trimmed down simulations (i.e., small number of users and/or short durations) as integration tests, so they go in src/it
- I use the gatling-sbt plugin (https://github.com/gatling/gatling-sbt) to drive the integration tests (via gatling-it:test or gatling-it:testOnly)
This arrangement gives me the ability to fully leverage my IDE (Intellisense, etc.) when working on simulations; facilitates running the integration tests aka test simulations from sbt (all project’s libraries are on the class path) w/o installing the bundle on my dev box; and provides a good separation between the code that depends on Gatling and the code that doesn’t.
Hope this helps,
What I am doing so far is similar:
- library code goes in main
- tests of that library code goes in test
- simulations that generate load goes in “it”
So far, I am just creating unit tests using ScalaTest. I would like to be able to trigger a Gatling run as part of some of those unit tests, so that the final test counts can include pass/fail stats from full gatling simulation runs. Any idea how to do that?
Answer to my own question:
“sbt test” will run both kinds of test, and the results are summarized. Yay!
HOWEVER: I do have a problem: I added a check which failed, but the test was still marked as pass. How do I make a Gatling test fail (from an SBT perspective) if a check failed. Through assertions?
Yep exactly, assertions are what control the status of a simulation, either through sbt or Maven integrations.
I must be doing something wrong:
setUp( … ).assertions( global.failedRequests.is( 0 ) )
[error] /Users/M47463/gatling-sbt/src/main/scala/com/cigna/common/UnitTest.scala:16: value is is not a member of io.gatling.core.assertion.AssertionWithPathAndCountMetric
I’m using 2.2.0-M3
You are missing a “count” between “failedRequests” and “is”.
I’m just blind…
global.failedRequests.count.is( 0 )