0

In a junit5 test class can weldinitiator config be specific (i.e different behaviour of mocks) for each method of the test class? Because I could only do and I only found one weldinitiator config for the whole test class but never for test methods specifically. Thank you.

  • Finally I couldn't use weld properly. It's a more complicate. I finally used just Mockito and it's much more simplier and less verbose in my tests. – Laurent Duvergé Nov 02 '19 at 06:44

1 Answers1

1

No, you cannot. WeldInitiator effectively provides a configuration for JUnit 5 extension that weld-junit uses to bootstrap itself and it is class-wide.

If you have an idea (pseudo code) of how this could look like, please create a GitHub issue on the project. Personally, I cannot imagine a way in which it wouldn't introduce more mess then order into testing. It is true that you can boot Weld on a per-test-method basis (in fact I think that's the basic mode), so in theory it could exist, but in the same time you can "workaround" this by creating an abstract class as a parent with your test logic and then as many subclasses as you like, each of which will have its own configured WeldInitiator - that should achieve exactly the same goal.

Siliarus
  • 6,393
  • 1
  • 14
  • 30
  • Interresting idea I haven't thougth about the abstract method. I'll try it and also I'll also try an other way using Junit5 hierarchicalContextRunner and let you know.... but I don't understand your sentence: "_It is true that you can boot Weld on a per-test-method basis (in fact I think that's the basic mode)_" Did you mean _on a per-test-**class**-basis_ ? – Laurent Duvergé Oct 21 '19 at 04:22
  • Weld-junit supports both lifecycles but from Junit5 perspective, per-method model should be the default. See their user guide - https://junit.org/junit5/docs/current/user-guide/#writing-tests-test-instance-lifecycle – Siliarus Oct 22 '19 at 13:09