-
Notifications
You must be signed in to change notification settings - Fork 57
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
Add CDI-Unit-Rule to use as alternative to CDI-Runner #74
Comments
Please provide a pull request and I'll merge and release. |
I've had a look at doing this. As it stands, I don't think it's possible, in general, from a JUnit Rule, because CDI-Unit creates a custom classloader to invoke the test class, but Rules delegate to other Rules by wrapping each other's Statements (in the same classloader). To make it work as a Rule, you would have to (a) get rid of the classloading (which would probably reduce CDI-Unit's abilities greatly, if it's even possible), or (b) construct a completely new Statement, and guess which test method to call based on the base Statement's Description. That won't work at all if (eg) another runner creates artificial test method names. In other cases, it might appear to work, but any other Rules would be unable to do their thing (because their custom Statements would be discarded by CdiUnitRule). I suppose this could work if you don't have any other Rules, and the other Runners don't do anything too interesting. It would be a real kludge though. For option (a), it might be possible to use something like https://deltaspike.apache.org/javadoc/1.4.2/org/apache/deltaspike/core/api/provider/BeanProvider.html#injectFields-T- with the caveat that the Test class itself would not be a real CDI bean. Another possibility might be delegating to another runner, but I haven't looked at the details of that approach. |
Hello, because of necessary integration with camunda-rule, I tried this. The points with the classloader are valid and at the moment I am a bit astonished how well it works. The main challenge I faced was, how to make the Testclass work in the CDI-Container since it normally contains @produces and @Inject.... To be able to do this, I created the Testclass once more "ApplicationScoped" and copied all fields. Until now that has only been done in ejb-cdi-unit with EjbUnitRunner which is on 3.1.4-Version yet. I would like to discuss it and if you think there is some merit, perhaps I can port that to the current cdi-unit-version: The Usage of the Rule together with the CamundaRule you can see at: EjbCamundaUnitRule |
Hello, It looks like we have the same issue with TestNG support. The practical consequence is that no interceptors are running to support I can also imagine the effects on the usage of |
TestNG listeners were implemented at #276. |
Please provide a JUnit Rule for CDI-Unit, so that I do not have to use a custom Runner.
This would also allow using different Runners in combination with CDI-Unit.
The text was updated successfully, but these errors were encountered: