I am asked to choose one and the best from these two for unit and integration tests-
1. RestAssured
2. Mockmvc
The application is in Spring and Spring Boot. I have read many blogs and no clear distinction is given or I couldn't find one. For rest assured, its neat and clean code and BDD style that makes it more readable. But doesn't sound a convincing point. Some of the tests are written using Mockmvc and I am trying to write the same in RestAssured to compare the same.
I know this may sound a theoretical question but I am unable to get points in favor of one and suggest which one is better and why. Looks like a choice of flavor to me. Any views and suggestions?
You would choose MockMvc for web layer testing. These tests will allow you to validate your controller classes properly handle respective HTTP requests. Since these are practically fine grained controller unit tests, you can additionally include them as part of your apps’ code coverage percentage with tools like JaCoCo. On a side note, these tests will likely run faster than integration tests since they won’t require the web server to run on.
RestAssured is used for integration testing in your Spring Boot app. When it comes to RESTful based API integration testing and validation, RestAssured offers convenient methods to create and execute your HTTP calls with custom headers, auth, content types, query parameters, payload content, cookies, etc.
To aid your comparison check out this article - Testing Spring Boot RESTful APIs using MockMvc/Mockito, Test RestTemplate and RestAssured - it has a good explanation and robust examples on the usage for RestAssured and MockMvc.
Related
I need to automate my web application functionality using rest assured.
Means there are no endpoints to verify the functionality of login module on the homepage and I need to automate same login Page functionality using Rest Assured.
Please, anyone, tell me to know the solution of my this query.
Rest-Assured is just a REST testing tool, you can't use it to perform UI functional testing.
You should use one of the tools dedicated to that, like Selenium.
The best way to go is to split your testing in two separate projects.
Backend functional testing with Rest-Assured (Making REST calls).
Frontend functional testing with Selenium (Using Selenium).
The application is using Minitest on Rails 4 with Capybara.
I'd like to write an integration or feature test that stubs a websocket connection (the application uses Faye as a client) to return a specific message (like I'm used to doing with Webmock).
Is this possible? If so, can you provide an example? My research has not turned up any examples.
Your research hasn't shown up any examples because it's not really what you're supposed to be doing in feature tests. Feature tests are supposed to be end-to-end black box tests where you configure the data as required for the app to generate the desired results and then all interaction is done via the browser (no mocking/stubbing which technically alter your apps code). Additionally when connections between the browser and a 3rd party service are involved there is nowhere in your app where you can mock it.
It may be possible to stub a websocket connection from the browser with a programmable proxy like puffing-billy, however it's generally cleaner to produce a small fake version of the 3rd party service for testing purposes (sinatra app, etc) and point the browser at that rather than the original service when you need to craft custom responses. Additionally, there are a lot of fakes already out there, depending on what service you are using (fake-stripe, fake-s3, etc), which may provide the functionality you're looking for.
I was through the integration testing documentation for Grails and I noticed this line:
Grails does not invoke interceptors or servlet filters when calling actions during integration testing.
source: http://grails.org/doc/latest/guide/testing.html#integrationTesting
Why is this? It would make my testing life a lot easier if Grails did invoke the filters. My project makes heavy use of filters and many of my controllers depend on my filters in order to do anything.
I was thinking about it and it seems like one could use groovy black magic to automatically execute the filters in an integration test. Has anyone already done this, or is this something that I'd have to write?
The environment used for integration tests is similar to what's available during run-app; Spring is active, plugins are loaded, a database is available, etc. Pretty much everything except for a web server. Without a server, there are no real requests, no servlet filters, and no Grails filters (which are wrappers for Spring controller HandlerAdaptors). When testing controllers you can access a request and response thanks to the Spring servlet API mock classes. But none of the real web request lifecycle is active, it's all just simulated.
You're right that it should be doable with some custom code. When you do this, please consider making it a plugin so we can all share :)
I've inherited a Grails app which makes calls out to a web service, using javax.xml.ws* classes and I'm trying to find a way to mock the web service based on the WSDL for the integration tests. I realize that I can use one of the java soap implementations to build this, but I'd rather stay in groovy.
So my question is, is there an idiomatic groovy way to build a web service based on a WSDL?
One approach that is pretty straightforward is to use Jetty to create a mock. It´s easy to create a mock that looks at the request and generates a response, especially if you´re using Groovy. For instance, create a template response file and use the XmlSlurper to fill in values. Then you can either start the mock in your tests or run it independently.
I found the following blog that roughly explains the basic concept:
http://olafsblog.sysbsb.de/lightweight-testing-of-webservice-http-clients-with-junit-and-jetty/
I am building a REST Web Service layer on top of a Rails app that will be used by an Iphone application. The response format is XML.
I would like to build some acceptance tests that should be external to the rails stack (and should test everything, including the http server). The test scenarios are quite complex, involving the process of searching/posting/reviewing an order. What would be the best solution to accomplish this?
a. Ruby script using curl/curb to fetch the request and Hpricot to parse the request
b. Selenium
c. ..
It would also be nice that those tests could be used as integration tests (therefore, run on every git commit). What integration solution would you recommend?
a. Integrity
b. CruiseControl
c. something else
I've used three approaches over this last few years
Active-resource
I found this to be too concerned with looking like active-record to be a great solution. In some cases I had to patch parts of it to work as I'd like a REST client to behave.
Rest-client
This gem is very good - well documented and does works as expected. I combined this with my own simple DSL and it's worked out better than a generic testing framework
XML over HTTP
I use this for performance testing. Very flexible but the learning curve is higher than Rest-client. If you go down this approach you could use the Net::HTTP core class or the HTTParty gem (I haven't tried this but it looks great>
A really good resource is this Net::HTTP cheat-sheet
For ad-hoc testing I've also found the Rest Client add-in for Firefox very useful.
Use selenium-rc in ruby mode and you'll be a happy camper. Webrat/Cucumber already do this for you so you can just put that in a second project and run the tests that way, all you'll have to do is override the host (so instead of localhost you'll be using your domain).
As to CI I'm afraid I don't know the best one.
you can't possibly mean mks integrity...if so, the answer is anything but. CC is a good CI tool. really good.