I am new to web services and would like to know what is the difference between Jersey client API and jersey test framework?
I would like to test my jersey REST web-services end points. Which is the the right one to use?
I am new to web services and would like to know what is the difference between Jersey client API and jersey test framework?
I would like to test my jersey REST web-services end points. Which is the the right one to use?
There are many HTTP client APIs out there (for example Apache HttpClient). You will need one to do client side testing. We will need to somehow access our services through HTTP, so one of these APIs will be needed for unit testing. Since you're already using Jersey, the Jersey Client API is a good choice. An example might look something like
As you can see the client API does not have to be calling our services. It is just interface to HTTP calls, with "Rest" features. If we wanted to run our own services, we would first need to deploy them to a container, whether a full blown server/container, or some embedded variant. Without a framework, a full test might look something like
The Jersey Test Framework allows us to do semi-integration/integration testing more easily, with options for more complex container deployments. The services can be launched into a lightweight embedded container (also different types) which will auto start and stop on running the unit tests. The framework is actually dependent on the Jersey Client API, so if you are using the framework, then you can use the Client API in your test cases. An example
You can see similarities, the
@Test
. That's because, we are making use of the client API. We don't need to explicitly configure theClient
, as the framework does this for us.So the choice really comes down to whether or not you want to use the Test framework. Either way you should know how to use the Jersey Client API, as you will be using it either way (that is unless you decide to just go with another HTTTP client API like HttpClient)
Read More