简体   繁体   English

集成测试一个asp.net Web Api项目

[英]Integration testing an asp.net Web Api Project

I'm currently working on a project that uses a form based UI which calls a Rest API in the backend. 我目前正在一个使用基于表单的UI的项目中,该UI在后端调用Rest API。 The UI is developed using HTML/JQuery/JavaScript and backend is developed using ASP.NET Web API. UI使用HTML / JQuery / JavaScript开发,后端使用ASP.NET Web API开发。 We are planning to write an End to End tests that simulates user actions and verifies the returned response, which will be in a json format. 我们计划编写一个端对端测试,以模拟用户操作并验证返回的响应(将以json格式)。

Question: 题:

I wanted to know what kind of frameworks/techniques are available that makes such integration testing easy(JavaScript-> WebApi). 我想知道有哪些可用的框架/技术可以简化集成测试(JavaScript-> WebApi)。 Also, if any one has done something similar and can share their experience? 另外,是否有人做过类似的事情并可以分享他们的经验?

My Research 我的研究

While doing some research online, I came across the following frameworks. 在进行在线研究时,我遇到了以下框架。 However, I havent worked with either of them, so am not aware of their pros and cons. 但是,我尚未与他们中的任何一个一起工作,因此不了解他们的优缺点。 I am planning on writing simple tests and evaluate their features 我打算编写简单的测试并评估其功能

Jasmin (http://jasmine.github.io/)  (JavaScript based framework)
Cucumber (http://www.specflow.org/) (BDD based framework)

Chander, as you are looking at end to end testing, could you not simply do CodedUI tests in Visual Studio. 在进行端到端测试时,Chander不能只在Visual Studio中进行CodedUI测试。 We currently do this for a similar architecture to you. 我们目前正在为您提供类似的架构。 They can be written by non-coders using the wizard and are very straightforward. 它们可以由非编码人员使用向导编写,并且非常简单。 Not to mention integrated into the Microsoft Stack so the experience for the tester in identifying why its gone wrong is much better. 更不用说已集成到Microsoft Stack中,因此测试人员在确定其出问题原因方面的经验要好得多。

Old question but I would like to mention a framework called RestFluencing that is trying to resolve exactly API integration testing. 这是个老问题,但我想提到一个名为RestFluencing的框架,该框架试图解决API集成测试的问题。

Rest.GetFromUrl("https://api.github.com/users/defunkt")
    .WithHeader("User-Agent", "RestFluencing Sample")
    .Response()
    .ReturnsDynamic(c => c.login == "defunkt", "Login did not match")
    .ReturnsDynamic(c => c.id == 2, "ID did not match") 
    .Assert();

Also if you have a class model you could use an JsonSchema validator: 另外,如果您具有类模型,则可以使用JsonSchema验证器:

public class GitHubUser
{
    public int id { get; set; }
    public string login { get; set; }
}

Validating: 证实:

Rest.GetFromUrl("https://api.github.com/users/defunkt")
    .Response()
    .HasJsonSchema<GitHubUser>(new JSchemaGenerator())
    .Assert();

Check out the GitHub page: RestFluencing 查看GitHub页面: RestFluencing

Disclaimer: I am the dev for that framework. 免责声明:我是该框架的开发人员。 Doing an full integration api testing in an easy way in C# has been something that I have been looking for a long time, hence this Fluent-style framework. 很长时间以来,我一直在寻找用C#轻松进行全面集成api测试的方法,因此就是这种Fluent风格的框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM