Skip to content

Instantly share code, notes, and snippets.

@swapnil-kotwal-sp
Last active August 29, 2015 14:06
Show Gist options
  • Save swapnil-kotwal-sp/825551dc436655eb7727 to your computer and use it in GitHub Desktop.
Save swapnil-kotwal-sp/825551dc436655eb7727 to your computer and use it in GitHub Desktop.
trait TestableSimulation extends Simulation with FlatSpecLike with BeforeAndAfter {
val props = scala.collection.mutable.Map.empty[String, String]
for { p <- sys.props if (p._1.startsWith("gatling")) } yield { props += p }
GatlingConfiguration.setUp(props)
val simClass = getClass.asInstanceOf[Class[io.gatling.core.scenario.Simulation]]
val cleanSimClassName = simClass.getSimpleName.clean
val outputDirectoryName = configuration.core.outputDirectoryBaseName.getOrElse(cleanSimClassName)
var selection = new Selection(simClass, outputDirectoryName, "no description")
def describe(desc: String) = selection = new Selection(simClass, outputDirectoryName, desc)
"Simulation" should "complete without assertion failures" in {
val runOutcome = new Runner(selection).run
val result = runOutcome._2 match {
case sim: Simulation if !sim.assertions.isEmpty => {
if (Assertion.assertThat(sim.assertions, DataReader.newInstance(outputDirectoryName))) GatlingStatusCodes.success
else GatlingStatusCodes.assertionsFailed
}
case _ => GatlingStatusCodes.success
}
assertResult(GatlingStatusCodes.success, "simulation has assertion errors")(result)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment