火炮:如何使用火炮载荷测试将测试场景标记为失败,并在某些报告中显示出来?

时间:2019-10-07 13:21:02

标签: artillery

我正在满足一些测试要求,当p95> 100ms时,我必须使负载测试失败。我在下面的测试代码段中写了:

config:
  target: "https://news.google.com"
  # Responses have to be sent within 10 seconds or the request will be aborted
  timeout: 10
  ensure:
      p95: 800
  phases:
    - duration: 10
      arrivalRate: 1

scenarios:
  - name: "Hit news google"
    flow:
    - get:
          url: "/dssw.js_data?_reqid=34556&rt=j"
          expect:
            - statusCode: 300
            - contentType: json

我希望这种测试方案在某种报告中可见,因为有多少个测试用例失败并通过了。大炮生成的报告仅显示性能统计信息,但如何根据测试性能声明显示该报告却在某种报告中失败。

1 个答案:

答案 0 :(得分:1)

一种选择是在 javascript 中实现一个钩子,它查看状态代码,如果认为状态失败,则通过 next 函数返回错误。

示例js钩子函数:

function exitOnFail(requestParams, response, context, ee, next) {
  const statusCode = parseInt(response.statusCode);
  if (statusCode > 399) {
    next(new Error(`${requestParams.url} StatusCode: ${statusCode}`));
  } else {
    next();
  }
}

并将钩子连接到请求:

config:
 ...
 processor: './scriptfile.js'

 ...

scenarios:
  - flow:
    - get:
        url: some/url
        ...
        afterResponse: 'exitOnFail'