cancel
Showing results for 
Search instead for 
Did you mean: 

CDI in JUnit

yuryshaban
Champ in-the-making
Champ in-the-making
Hello!

I'm using nice JEE7 stuff named CDI. It's very useful one and I'm (personally) happy that activiti works with CDI properly. Thanks a lot!

But I've got a question:
at runtime CDI works great, but, seems, if I'm trying to run JUnit tests - CDI injects of <? extends JavaDelegate> don't work.
In my case 'CDI injects' is using @Inject to get local EJB beans.

Is it possible to use CDI injecting with JUnit? If it is - please, explain, how.

Thanks in advance!

P.S.
We are using Activiti 5.16.3 and akquinet/needle.
2 REPLIES 2

pkonyves
Champ in-the-making
Champ in-the-making
Hi, We bootstrap Weld in our unit test. If I have time I can extract some code for you. It works quite nice. However for injecting @EJB beans, CDI will not be enough, you will need Arquillian for that. We don't use EJB

Or, a simpler solution is to start JUnit from a deployed servlet. But it's not that fancy Smiley Happy

yuryshaban
Champ in-the-making
Champ in-the-making
Thanks a lot for the quick answer!

I've hoped to got off lightly, but you're right: to do complex (integration) test I have to use little bit more complex approach then a plain JUnit.
Thank you again.