users@jersey.java.net

Re: [Jersey] Unit testing resources

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 26 Jun 2008 09:01:46 +0200

On Jun 25, 2008, at 11:01 PM, Martin Probst wrote:

>>>> Tis hard when classes need to be deployed e.g. like servlet, JAX-
>>>> WS or EJB.
>>
>> I think one can still to TDD of resource classes but the focus is
>> on the HTTP interface, which IMHO is not a bad thing since this
>> is what matters most?
>
> It depends. I personally think that testing a resource class via
> the HTTP interface is a functional test, not a unit test. You don't
> test the micro functionality of single methods, but rather the
> whole interface in and out. There should be a way to run your code
> directly without any HTTP stuff in between ...
>
>> If you could extend from say a class JerseyUnitTest that helped
>> you 'deploy' or 'mock up' just what you need and you could utilize
>> the Jersey client API you might get reasonable rapid test driven
>> development. Would that work for you?
>
> Currently I'm also developing a Spring-based application. I've
> created a class "SpringBasedTest" that sets up the dependency
> injection for all sub classes, and this makes it pretty easy to
> implement tests. This should be possible for Jersey too - JUnit has
> some hooks to integrate into, e.g., the @RunWith annotation.

Hmm... so we would need to 'mock up' stuff that could be injected
like UriInfo, HttpHeaders and Request with information that is
important for the test. There is actually not that much information
really, the full set is: the HTTP method, the base URI, the request
URI, and the list of headers. Do you have any ideas how that could be
easily expressed in such unit tests?

Paul.