Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the language that Rest Assured can work with

Tags:

rest-assured

I have a question about Rest Assured, Is it work with only Java tests? Or I can use It with C# for example?

Thanks

like image 345
Tasnim Zuhod Avatar asked Sep 23 '16 22:09

Tasnim Zuhod


1 Answers

Edit: btw, there is a .net implementation as well it seems:

https://github.com/lamchakchan/RestAssured.Net

This is what the homepage says:

Testing and validation of REST services in Java is harder than in dynamic languages such as Ruby and Groovy. REST Assured brings the simplicity of using these languages into the Java domain.

http://rest-assured.io/

But I would personally argue that with tools such as rest-assured you can test your service regardless of the implementation language. You want to think of your system as black box.

On a related note, your comment that you'd like to write unit tests against a REST endpoint is somewhat incorrect if we stick to the jargon strictly.

Some argue that in such cases the tests should be written in a way, that they are agnostic of the technology used for implementing said service. For a general description please see

https://en.wikipedia.org/wiki/Black-box_testing

The benefit of this approach is that these higher level tests can be used to test even multiple implementations of said service. Imagine you're working in a microservices environment and you realize the need to rewrite your ruby application in java, but you cannot change your API (you cannot force users to change because of your internal implementation changed, even if it's inside your company, people will not talk to you in the cafeteria).

That being said, there is something to be said for not creating a polyglot development environment as well. Who is going to write those tests? If it is the same group and the tests reside in the same place (repository), you are truly better off using the same programming platform.

Note: I am not arguing you should move this black-box away from your source code, but it may be the setup sometimes.

On the contrary, lower level tests such as unit test must be stored along with the code as they specifically test the implementation and not only functionality.

So now what? You're in .NET, so probably you're better off using a tool from the "neighborhood" otherwise you may over complicate the developer environment setup for your team.

RestSharp is mentioned quite a few times here in SO.

var client = new RestClient("http://example.com");
// client.Authenticator = new HttpBasicAuthenticator(username, password);

var request = new RestRequest("resource/{id}", Method.POST);
request.AddParameter("name", "value"); // adds to POST or URL querystring based on Method
request.AddUrlSegment("id", "123"); // replaces matching token in request.Resource

// easily add HTTP Headers
request.AddHeader("header", "value");

// add files to upload (works with compatible verbs)
request.AddFile(path);

// execute the request
IRestResponse response = client.Execute(request);
var content = response.Content; // raw content as string

// or automatically deserialize result
// return content type is sniffed but can be explicitly set via RestClient.AddHandler();
RestResponse<Person response2 = client.Execute<Person>(request);
var name = response2.Data.Name;

License is Apache 2, maybe you should have a look and combine with your own general purpose testing framework.

like image 155
dbalakirev Avatar answered Jan 03 '23 16:01

dbalakirev