2017-01-05 55 views
0

我是来自postman的api测试新手。我经历了几篇关于 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; 
} 

给出无论上述测试程序是正确的。? 在调用post请求并针对上述模型的部门控制器获取请求时,测试所有东西。

回答

0

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

测试用例应该是

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

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

另外,如果你正在处理的不仅仅是测试,还要设计你的API并记录它们,然后看看http://myapic.com。它是端到端API设计记录和测试的绝佳工具。