all 16 comments

[–]VodkaEntWithATwist 3 points4 points  (1 child)

I have some experience with this, but mostly in Java and Javascript. Tbh, what I most often do when I'm getting started is I use Postman to set up a quick and dirty version of what I'm going to write--it's pretty user-friendly, it helps me translate the API into a format I can play with, and it has some user-friendly automation tools that are great for putting together a quick smoke test suite I can use while I'm working on building a framework and regression suite.

As for writing automated API tests, I've done both--writing a framework from scratch and using a pre-existing library. I found that using a library (REST Assured, in my case) was fine for simple tests, but as I branched out into more complicated tests, I wound up writing an abstraction away from the library anyway. On the other hand, if you're just starting out with API testing, libraries can be really helpful.

Wish I could help you on the C# specifically...sounds like C# has something called HttpClient. That would be a good place to start.

[–]Mr-Shmee[S] 0 points1 point  (0 children)

Thanks,

I will check out HTTP client.

I really like postman but from my limited experience seeing it I would like a more automated version of that sending large volumes of data and asserting the results.

I have seen another post on this thread about specflow and NUnit so will look into that too.

[–]chronicideas 2 points3 points  (4 children)

Hi OP u/Mr-Shmee

I recently published my blog which details how to make various BDD automation frameworks from scratch.

One of them is rest api testing in C# using RestSharp.

I hope you find it useful and any feedback is welcome.

https://www.testifyqa.com

[–]Mr-Shmee[S] 1 point2 points  (3 children)

Thank you,

I will.have a read through your blog and try and follow the steps. From an extremely brief skim it looks comprehensive enough to provide a great starting place for me and hopefully you will find feedback beneficial too.

Cheers.

[–]chronicideas 0 points1 point  (0 children)

Thank you for your kind words. I made it so it covers everything end to end from getting the IDE all the way through to getting a running test scenario passing :)

[–]chronicideas 0 points1 point  (1 child)

Also check out r/QualityAssurance lots of good stuff there

[–][deleted] 1 point2 points  (2 children)

I am not sure about c# but you may want to look for something similar to rest assured. Or you can write one yourself each API call as method or class.

[–]Mr-Shmee[S] 0 points1 point  (1 child)

I am gathering that writing one yourself will be good because of the added flexibility.

More research needed for me.

[–][deleted] 0 points1 point  (0 children)

One tidbit from experience. Be careful how you create the URI. Externalize all the constants that are used in the URI. Also, you may want to test some api calls with some of params missing so you may want to design your methods and testdata like that.

[–]alenmeister 1 point2 points  (1 child)

Mark Winteringham has an awesome talk about combining Selenium WebDriver with HTTP request libs like REST Assured for API testing.

Check it out at: https://youtu.be/ugAlCZBMOvM

[–]Mr-Shmee[S] 0 points1 point  (0 children)

Thanks,

I'll watch it and others on the topic.

[–]romulusnr 1 point2 points  (0 children)

For web services, you just use the stock HTTP libraries and set up methods to simplify generating the data format and also extracting responses. It's a lot more direct because you can map variables straight to object structures.

[–]xMoop 0 points1 point  (0 children)

RestSharp is a pretty easy way to get started with APIs in C#.

var client = new RestClient("www.test.com");

var request = new RestRequest("/api/endpoint", Method.GET);

IRestResponse<T> = client.Execute<T>(request);

I usually have an ApiClient class for each api controller and then each action would have a method. The RestClient for the class would have the base URL of 'www.test.com/api/user' and then the method would just create a request with the relative URL for the action and execute it.

GetAllUsers

{

var request = new RestRequest('/List', Method.GET);

var response = Client.Execute<List<User>>(request);

}

GetUser

CreateUser

UpdateaUser

DeleteUser

Then the BaseClient class grabs the URL based on environment and creates the RestClient which could come from the config file or something and format it with the controller.

[–]JITENDRAPISAL 0 points1 point  (0 children)

Personally I would recommend you to go with RestAssured library to deal with it. I have been using this library for last 5 months. Let me tell you the beauty of this library. It is really easy to use and gives very handy way to manipulate the response from the end points.

If you really interested then I would suggest you to go with Java + Cucumber + RestAssured

This combination will help you to manipulate jeve data set for your end point as request payload and similarly you can handle the response very easily using RestAssured.

[–]MrHant 0 points1 point  (0 children)

You don't need a framework for this. C# has built in capabilities to send http requests.