>> My question is what are the best practices for writing test suites of
>> this sort using the JerseyTest framework and JUnit 4? Currently the
>> only annotations that are employed are @Test, @Before and @After.
>> Ideally we'd like each test to be part of a suite of tests that has a
>> WebTestContainer created at the beginning of the entire suite of
>> tests rather than each individual test and have the WebAppDescriptor
>> replaced @Before each individual @Test.
>>
>
> Currently JerseyTest is a bit limited in this respect. I think what we
> require is an AbstractJerseyTest from which you can extend and decide
> on the policy of starting and stopping the test container.
>
> I think the only way you can control this at the moment is to right
> your own test container factory to control stop and start per test
> class instantiation.
>
> Any thoughts Pavel?
I did a little investigation about that and I have some "demo" solution
to first problem.
It should be relatively easy to modify jersey test to start container
only at the beginning of processing individual @Test annotated methods
and stop it after all tests are executed. JUnit has @BeforeClass and
@AfterClass annotations that are used mainly for this but annotated
methods have to be static and are called before JerseyTest class
instantiation so I can't use that. I've added some basic logic to setUp
and tearDown methods instead and it looks like like its working.
Replacing WebAppDescriptor before each individual test is basically
undeploying previous application and deploying new one without
restarting whole container (if I understood it correctly).
We probably can redesign TestContainers start and stop methods to take
parameter and decide whether stop whole container or just current
"application". This is usecase which I didn't see at first - so we have
three test scenarios now:
1) current state - container is being restarted after each @Test method
2) without restarts - container is started just once and application is
deployed just once
3) undeploy/deploy - application is restarted before each @Test
Question one is - what scenarios do we want to support?
And second question - How can user/test activate wanted behavior ..
currently I have case 2 implementation and you need just override method
persistentContainer in JerseyTest. I would like to have test setup as
easy as possible, so I can imagine something like overriding method /
setting parameter "testContainerType" ..
I don't want to start anything bigger without your opinions, so.. any
thoughts?
Thanks,
Pavel
>
>
> As for a suite of tests that is be a little different to what we are
> used to. If you can give an example of how you would like to write
> your code we might be able to use that as a template to support that
> style.