现在我正在尝试对所有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))```
答案 0 :(得分:3)
您可以将Gatling断言添加为Global断言。这将与Karate 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.
全局断言将在加特林报告中显示为单独的部分。这是空手道加特林的有用功能。空手道加特林的报告中还将显示测试特定的失败。例如,如果这是您的情况
Scenario: My First Sample Scenario
Given url endpointUrl
And header karate-name = 'Feature 1_Scenario3'
When method get
Then status 200
如果状态代码未响应为200,则该状态代码也会记录在“空手道加特林”报告中。
加特林的助手: https://gatling.io/docs/current/general/assertions/#scope