sahaya / rest-assured

Automatically exported from code.google.com/p/rest-assured
0 stars 0 forks source link

Mockito Integration #187

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It would be great if REST-assured could be integrated into Mockito. This does 
not mean to hand over the REST-assured code to the Mockito project, but instead 
I mean that a user can write Mockito assertions that will invoke REST-assured 
code (just like Hamcrest is integrated with Mockito, but is not pat of it).

This would be very beneficial, because (a) it makes no sense to have two times 
a complete sete of BDD syntax like given(), when(), then() etc. Also it would 
allow to write assertions that include both, non-REST-assured and REST-assured 
assertions in one single setup.

Example:

The following example shows how to set up a test case that uses Mockito to mock 
some classes, and that uses REST-assured to run a test:

when(this.em.find(MyJpaEntity.class, 0)).thenReturn(new MyJpaEntity());
given().header("Accept", 
"application/xml").then().expect().statusCode(200).and().body("MyXmlElement.@myX
mlAttribute", is("MyValue")).when().get("my/url");

The example shows that there are two BDD phrases named "when()", one from 
Mockito and one from REST-assured. It would be much, much better to be able to 
write a mix like this:

given().header(...).when(jpaConstraint).and(RESTconstraint).get().thenReturn(Jpa
Result).andVerify(RESTexpectations);

Original issue reported on code.google.com by headcrashing on 13 Aug 2012 at 8:35

GoogleCodeExporter commented 9 years ago
Mockito is a mocking framework and REST Assured is an integration testing 
framework. REST Assured (to my knowledge) is mostly ran on another JVM than the 
code being tested and it's not trivial to handle mocking of classes in 
different JVM's (something like Arquillian could help to solve it). The purpose 
of REST Assured so far is not to mock or stub anything but rather testing the 
complete stack from the REST layer perspective. This is much different than 
what you're proposing. I'm not saying it's a bad idea and it you want to pursue 
it I'll try to help you as much as I can but personally I don't have enough 
time to do this.

Regards,
/Johan

Original comment by johan.ha...@gmail.com on 15 Aug 2012 at 6:16

GoogleCodeExporter commented 9 years ago

Original comment by johan.ha...@gmail.com on 25 Sep 2012 at 6:07