8

I'm looking at writing at automated tests to cover regression testing in respect of Restful API's.

I have familiarity with how to do this in Java using Rest Assured, however the company I currently work for is a .Net house so it would make sense to write the automated tests in Visual Studio using c# as the programming language.

My question is whether anyone has any advise on testing tools that can be utilised with Visual Studio/C#, or point me in the direction of how I might go about building a framework in C#. Essentially, coming at this from the ground up so any help would me much obliged!

Andy

4

You can use the combination of any unit testing framework (like NUnit, MSTest, XUnit) with additional nuget packages for the work with REST API itself

Also I recommend using the Json.NET (https://www.newtonsoft.com/) nuget for convenient work with the request/response JSON data, it's much easier to work with the deserialized objects that with the plain JSON strings.

4

Writing an API test in Visual Studio can be done with:

  • NUnit or MSTest as your Test Runner ** NUnit and the TestAdapter are available on Nuget
  • An http client, like .Net's HttpClient ** This is in the System.Net namespace
  • (Optional) Json.Net for parsing responses ** Also avaiable on Nuget

Your test will look something like this:

[Test]
public void Record01StatusCode()
{
    // Arrange: Define the endpoint to be tested
    string requestUri = "http://foo.bar/record/01";
    // Act: Make the request (Note: MakeRequest is a method I wrote in another class)
    HttpResponseMessage response = httpClient.MakeRequest(HttpMethod.Get, requestUri);
    // Assert: The request returns a successful response
    Assert.IsTrue(response.IsSuccessStatusCode, "Response was not a success status code!");
}
0

You can try

0

You can use Jmeter or Postman to test the APIs. It will be easy to form the payload . If further to automate can invoke Jmeter through Jenkins, command line or batch file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.