【问题标题】:API testing using post man使用邮递员进行 API 测试
【发布时间】:2017-05-19 17:34:44
【问题描述】:

我是 postman 的 api 测试新手。我浏览了几篇关于 api 测试。但我不知道我们可以做多深的测试。 另外我们如何为发布请求编写测试。我有以下部门模式类 来自我的网络 API。

    [Key]
    public int DepartmentId { get; set; }

    [Required]
    [Display(Name ="Department Name")]
    public string DepartmentName { get; set; }

    public string Description { get; set; }

    public bool IsActive { get; set; }

我使用的示例获取请求如下所示

var body = JSON.parse(responseBody);
if(!body.DepartmentId)
{
tests["department id must exists in  response"]=true;
}
else
{
tests["department id exists in response"]=true;
}
if(typeof body.DepartmentName !='string')
{
tests["department name must be type string"]=true;
}
if(responseCode.name.has("OK"))
{
tests["Status code name has string OK"] = true;
}

上述测试程序是否正确。? 对于上述模型,在调用发布请求和获取针对部门控制器的请求时要测试的所有内容。

【问题讨论】:

    标签: testing asp.net-web-api2 postman


    【解决方案1】:

    您不必编写 2 个测试用例来测试 +ve 和 -ve 场景。您需要做的就是编写一个测试用例,它会根据场景通过或失败。例如,让我们考虑您的 DepartmentId

    测试用例应该是

    tests["department id must exists in  response"]= body.DepartmentId? true : false;
    

    根据您的部门 ID 是否存在,您的测试用例将通过(标记为绿色)或失败(标记为红色)。

    或者,如果您不仅要处理测试,还要设计 API 并记录它们,请查看 http://myapic.com。它是端到端 API 设计文档和测试的绝佳工具。

    【讨论】:

      猜你喜欢
      • 2018-09-23
      • 1970-01-01
      • 2019-05-14
      • 1970-01-01
      • 2017-12-17
      • 2022-07-28
      • 2021-05-12
      • 2019-11-01
      相关资源
      最近更新 更多