testing - 以编程方式执行 Gatling 测试

标签 testing performance-testing cucumber-jvm gatling

我想使用 Cucumber JVM 之类的东西来驱动为 Gatling 编写的性能测试。

理想情况下,Cucumber 功能会以某种方式动态构建场景——可能会重用类似于“高级教程”中描述的方法的预定义链对象,例如

val scn = scenario("Scenario Name").exec(Search.search("foo"), Browse.browse, Edit.edit("foo", "bar")

我查看了 Maven 插件如何执行脚本,我也看到了使用 App 特征的提及,但我找不到后者的任何文档,这让我感到震惊,其他人可能会想要之前做这个...

任何人(一个 Gatling 菜鸟)都可以指出一些文档或示例代码的方向来说明如何实现这一点吗?

编辑 20150515

所以再解释一下:

我创建了一个 trait,它旨在构建一系列我认为由 Cucumber 步骤触发的 ChainBuilder:

trait GatlingDsl extends ScalaDsl with EN {

  private val gatlingActions = new ArrayBuffer[GatlingBehaviour]

  def withGatling(action: GatlingBehaviour): Unit = {
    gatlingActions += action
  }
}

GatlingBehaviour 看起来像这样:

object Google {

  class Home extends GatlingBehaviour {
    def execute: ChainBuilder =
      exec(http("Google Home")
        .get("/")
      )
  }

  class Search extends GatlingBehaviour {...}

  class FindResult extends GatlingBehaviour {...}
}

在 StepDef 类中:

class GoogleStepDefinitions extends GatlingDsl {

  Given( """^the Google search page is displayed$""") { () =>
    println("Loading www.google.com")
    withGatling(Home())
  }

  When( """^I search for the term "(.*)"$""") { (searchTerm: String) =>
    println("Searching for '" + searchTerm + "'...")
    withGatling(Search(searchTerm))
  }

  Then( """^"(.*)" appears in the search results$""") { (expectedResult: String) =>
    println("Found " + expectedResult)
    withGatling(FindResult(expectedResult))
  }
}

我的想法是我可以通过类似的方式执行整个 Action 序列:

val scn = Scenario(cucumberScenario).exec(gatlingActions)
setup(scn.inject(atOnceUsers(1)).protocols(httpConf))

然后检查报告或在测试失败时捕获异常,例如响应时间太长。

似乎无论我如何使用“exec”方法,它都会尝试立即执行它,而不是等待场景。

我也不知道这是否是最好的方法,我们想为我们的 Gatling 测试构建一些可重用的 block ,这些 block 可以通过 Cucumber 的 Given/When/Then 样式构建。是否有更好的或已经存在的方法?

最佳答案

遗憾的是,目前让 Gatling 直接启动模拟实例是不可行的。

并不是说它在技术上不可行,而是您只是第一个尝试这样做的人。 目前,Gatling 通常负责编译,只能传递要加载的类的名称,而不是实例本身。

您可以从 fork io.gatling.app.Gatlingio.gatling.core.runner.Runner 开始,然后提供 PR 来支持这个新的行为。前者是主要入口点,后者可以实例化和运行模拟。

关于testing - 以编程方式执行 Gatling 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30194555/

相关文章:

java - 带有Gradle for Java的 cucumber

Cucumber/gradle 示例没有生成报告?

javascript - yup.js 在条件时检查数组

java - 在什么情况下Java性能会随着内存的增加而降低?

java - 插入排序的比较时间复杂度

php - 性能、mysql 查询与 php 数组

grails - 从 grails 插件执行 Cucumber Specs

symfony - 如何在 Symfony 中实例化 Autowiring 服务?

R ggplot2 : geom_text error (object not found). .. aes() 冲突?

java - 我应该注入(inject)一个 HashSet 来存储监听器以实现可测试性吗?