I'm using JUnit 5.3.0-RC1, trying to implement an extension for the new TestInstanceFactory
interface. (I want to get the objects from Weld for CDI injection etc.)
If I implement TestInstanceFactory
I can create my own instances. If I also implement AfterEachCallback
I can clean them up (shut down Weld) after each test. So far, so good.
However: for this I have to assume TestInstance.LifeCycle.PER_METHOD
. If the test class uses TestInstance.Lifecycle.PER_CLASS
I would have to detect this and wait until AfterAllCallback
before destroying Weld. But ExtensionContext.getTestInstanceLifecycle
is declared as Optional
, so I may not be able to tell which Lifecycle is active.
Is there a way of having JUnit simply tell me when to destroy the instance? It would be nice to have an extension like TestInstanceDestructor
, which would be called whenever JUnit has finished using the test instance.
Secondly, AfterEachCallback
is never called for @Disabled
tests, which means I can't clean up the instances which were created through my TestInstanceFactory
. Starting Weld is kind of expensive, so ideally I'd skip doing that work for disabled tests anyway. Is there some way I can tell which instances are being created for disabled tests?