-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Intercept unit test method #144
Comments
I don't think that it's possible in the current implementation but @manovotn would know for sure ;-). |
Hi @graben It is not possible. If memory serves, this wasn't doable due to how JUnit handles test instances. |
I am not sure why do you need this but note that in order to "intercept" (in a non-CDI manner) test methods, you can do that fairly simply by writing a custom JUnit 5 extension. Maybe that would help? |
Hm, it could be possible in JUnit 5.7+ with |
Yes, that might be the trick to switch weld creation to TestInstanceFactory lifecycle method. Maybe look at https://github.com/cschabl/cdi-unit-junit5 |
That's interesting, didn't know about it. But note that this brings some limitations:
|
It seems they are doing full discovery which is very inefficient if there are more tests and possibly interferes with configs between tests. We OTOH try to let users create minimal archive but for that, we need to know what classes are to be added to the CDI container... |
Also, didn't we have a similar conversation somewhere with @Vampire? |
@graben what was the original use case why you needed to intercept instances? The more I think about it, the more it seems to me that going for |
@manovotn: I try to test my own transational cdi extension that's why my test methods uses @transactional |
Ok, let's keep this issue open for more discussion. @mkouba what's your take on whether it is worth it? |
I cannot remember such a discussion, but that could also be caused by my holey memory. But another thing I remember is, that somehow (at least with the JUnit Jupiter and then probably also the Spock variant) the test instance provided by the test framework was put in place of an own instance generated by Weld. Don't remember the gory details right now. |
Ok, I might be misremembering it then, sorry for the noise.
Yes, this is basically what we're talking about here. We'd need to be able to bootstrap Weld and use it to provide test instance way sooner for it to be interceptable. |
Theoretically, this could be done for However, that creates discrepancy between how However, the above still presumes that the test class can become managed bean as per specification. Mainly the no-arq constructor and not being an inner class presenting a potential blocker. To be able to deal with those, we'd still need the fallback option, as outlined above. I'll get back to this next week since I need to refresh my memory on how exactly do we integrate with JUnit. From there, I'll see if I can spot some reasonable way to cobble this together... |
Is it possible to do intercepting for test method itself? Handle test instance as a bean.
The text was updated successfully, but these errors were encountered: