如何在gatling中使用多个场景的断言?

问题描述 投票:2回答:1

现在我正在尝试对我所有的api进行性能测试。我已经创建了一个具有不同场景的特征文件(每个场景都有不同的标签)。现在我想在不同场景下使用不同断言的平均ResponseTime上使用断言。

val Performance1 = scenario("Performance1").exec(karateFeature("classpath:mock/Testing1.feature@Performance"))
val Performance2 = scenario("Performance2").exec(karateFeature("classpath:mock/Testing2.feature@v3ContentMeta"))

val v4SearchTest = scenario("SearchTest").
group("SearchTesting") { exec(karateFeature("classpath:mock/Testing1.feature@Performance"))
}

setUp(
  (Performance1.inject(rampUsers(10) over (5 seconds)).protocols(protocol)),
    Performance2.inject(rampUsers(10) over (5 seconds)).protocols(protocol)
  ).assertions(details("SearchTesting").responseTime.mean.lte(680))```
gatling karate
1个回答
3
投票

您可以将Gatling断言添加为全局断言。这将与空手道加特林完美配合。这是我们尝试过的示例场景

setUp(
    firstScenario.inject(
      nothingFor(5 seconds), // Pause for a given duration
      atOnceUsers(10), //Inject 10 Users at once
      constantUsersPerSec(10) during (20 seconds), // Induce 10 requests on every second and continues this process for 30 seconds
      rampUsers(10) over (10 seconds) // Linear Ramp up of the user
    ).protocols(protocol),

    secondScenario.inject(
      nothingFor(10 seconds), // Pause for a given duration
      atOnceUsers(20), // Inject 10 Users at once
      constantUsersPerSec(10) during (10 seconds), // Induce 10 requests on every second and continues this process for 40 seconds
    ).protocols(protocol),

    thirdScenario.inject(
      nothingFor(15 seconds), // Pause for a given duration
      rampUsers(20) over (1 minute) // Linear Ramp up of the user
    ).protocols(protocol),

    fourthScenario.inject(
      nothingFor(20 seconds), // Pause for a given duration
      constantUsersPerSec(10) during (20 seconds), // Induce 10 requests on every second and continues this process for 20 seconds
    ).protocols(protocol)

  ).assertions(
    global.responseTime.max.between(100, 5000),
    global.failedRequests.percent.is(0),
    global.successfulRequests.percent.gt(90)
  ).maxDuration(10 minutes) // Configuring the maximum duration of your simulation. It is useful when we need to bound the duration the simulation when we can’t predict it.

全局断言将作为Gatling报告中的单独部分显示。这是空手道加特林的有用功能。测试特定的失败也将显示在空手道加特林的报告中。例如,如果这是您的方案

Scenario: My First Sample Scenario
    Given url endpointUrl
    And header karate-name = 'Feature 1_Scenario3'
    When method get
    Then status 200

如果状态代码未响应为200,则也会记录在空手道加特林报告中。

在Gatling中断言:https://gatling.io/docs/current/general/assertions/#scope

© www.soinside.com 2019 - 2024. All rights reserved.