【问题标题】:How can I run automated tests to check the average response time of a rest API?如何运行自动化测试来检查 REST API 的平均响应时间?
【发布时间】:2017-03-28 19:54:45
【问题描述】:

我有一个 RESTful API,我想在一天中的随机时刻运行一些测试,以检查平均响应时间。我无法使用 Postman 的 Collection Runner 来做到这一点。是否有其他工具可以让我这样做,或者我必须自己编写?

【问题讨论】:

标签: rest api automated-tests postman


【解决方案1】:

您可以使用Pingdom 之类的服务从您的 API 中检索调用,或者您可以使用软件(商业或开源,Zabbix 还在吗?)来监控您的 API,或者(如果您不需要太多好处)您可以自己编写一个在 cronjob 中运行的脚本,并将 API 的响应时间保存在 txt 文件(或任何您想要的位置)中以供进一步检查。

这里有一个小例子,在 php 中,但你可以很容易地适应你的喜好。语言。

// I don't know how much will it take to run the API request
set_time_limit(0)

$start = microtime(true);

$result = executeApiCall()

$executionTime = microtime(true) - $start;

storeExecutionTime($executionTime)

function storeExecutionTime($time) {
   // store the data somewhere
}

【讨论】:

    猜你喜欢
    • 2015-08-07
    • 2015-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-07
    相关资源
    最近更新 更多