junit4 icon indicating copy to clipboard operation
junit4 copied to clipboard

Parameterized: added new @StaticParameter annotation

Open meden opened this issue 9 years ago • 4 comments
trafficstars

The new annotation allows to inject parameterized values in static test members.

This is useful when one has to run a parameterized test case against parametric expensive resources.

meden avatar Nov 01 '16 09:11 meden

Can you please provide an example where this is useful?

marcphilipp avatar Nov 01 '16 09:11 marcphilipp

I made this to do an integration test of a mail processor. The processors uses a MessageBatch abstraction which insists on different mail stores (i.e. protocols). As you can imagine, the interface is the same, but the behavior is not. I set up only one parametric test case, where different MessageBatch implementations get tested. Each of them, though, requires to connect to a different store, which is a slow task to do at each test method.

An alternative (which I implemented) without static parameter injection is to use a @ClassRule whith static fixtures, from which pull needed mail folder and such. IMHO, this solution is less straightforward than a static injection.

BTW, I can understand this is a bit a corner case.

meden avatar Nov 01 '16 11:11 meden

I am not sure I completely understand, but it sounds like your use case is a bit of a stretch for Parameterized. You aren't testing one thing with multiple values, you are testing multiple implementations.

Can you provide an example of what your test looks like with static injection and what it looks like with @ClassRule?

kcooney avatar Nov 01 '16 13:11 kcooney

I think that something like @BeforeParameterRun in #45 would be a solution to your problem, too. Am I right?

stefanbirkner avatar Nov 10 '16 07:11 stefanbirkner