Chander Shivdasani
Chander Shivdasani

Reputation: 10131

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. The UI is developed using HTML/JQuery/JavaScript and backend is developed using 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.

Question:

I wanted to know what kind of frameworks/techniques are available that makes such integration testing easy(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)

Upvotes: 0

Views: 888

Answers (2)

Douglas Jimenez
Douglas Jimenez

Reputation: 307

Old question but I would like to mention a framework called RestFluencing that is trying to resolve exactly API integration testing.

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:

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

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.

Upvotes: 1

Steve Newton
Steve Newton

Reputation: 1078

Chander, as you are looking at end to end testing, could you not simply do CodedUI tests in Visual Studio. 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.

Upvotes: 1

Related Questions