6

我正在尝试通过 Gatling 运行一个简单的性能测试。我使用 maven 来运行该过程。为了在代码更改破坏我的 gatling-tests 时轻松获取,我希望 maven-build 失败。我已确保添加<failOnError>true</failOnError>到我的 pom.xml 文件中。

我当前的脚本是这样的:

class MySim extends Simulation {
    val httpProtocol = http.baseURL("http://localhost:8080")
    val scn = scenario("Test")
         .exec(http("request_1")
           .get("""/helloworld""")
           .check(status.is(200))
         )
    setUp(scn.inject(ramp(1 users) over (1 seconds))).protocols(httpProtocol)
}

我使用 maven(使用 gatling-maven-plugin)运行构建,mvn clean gatling:execute它总是会成功。(即使服务器没有运行)。我正在寻找一种方法来确保当 gatling-test 失败(或失败百分比过高)时 maven 构建失败。

4

2 回答 2

9

所以我想出了一个解决方案:我所要做的就是在 setUp 中添加断言,并使用我想要的标准。因此,如果成功率低于 90%,则以下代码将失败 maven-build。

setUp(scn.inject( ... ))
    .protocols(httpProtocol)
    .assertions(
        global.successfulRequests.percent.greaterThan(90)
    )
于 2014-09-04T12:28:31.690 回答
3

您必须使用断言API。

于 2014-09-04T12:43:42.213 回答