users@jersey.java.net

[Jersey] Re: Clearing Resource State Between _at_Tests

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Tue, 03 Jul 2012 16:57:38 +0200

Hello Timothy,

Jersey application is currently always restarted, but always with the
same application descriptor. So it will reuse some singletons etc.,
which is most likely your problem.

Ugly workaround would be creating only one test per JerseyTest
descendant, but I that will most likely lead into huge number of java
classes with repeated code (well, inheritance should help you, but
anyway..).

Please file an enhancement request for Jersey Test Framework and
describe your usecase, small reproducible testcase would be great. It is
solvable by moving AppDescriptor and TestContainer creation from
constructor to setUp method, but we'll need to investigate whether it
won't be too big performance loss. (But we can always make this
configurable).

Thanks,
Pavel

On 6/26/12 5:20 PM, Timothy Rodriguez wrote:
> Hi all,
>
> I'm currently using the JerseyTest framework to test some of my
> Resources but I am having issues clearing the state of the resources
> between tests. I want each of the tests to be fully separable, so I
> want the application to have fresh instances of all its resources
> between tests.
>
> It looks like JerseyTest doesn't do that by default, so I opted for
> manually invoking the tearDown and setUp methods in my @Before method
> to manually reset the container. However, it looks like this does not
> fully reset the container as the stop method on the WebApplicationImpl
> does not set the isInitiated flag to false--causing the same instances
> of the resources to be used on startup.
>
> What is the best method for ensuring tests are fully separable? Is
> there a way to force a reinitiaion in my tests oe is there another way
> I should be going about this?
>
> Thanks,
>
> Tim
>
>