-
1. Re: Unit testing CDI beans
jorgemoralespou_2 Sep 16, 2014 6:43 AM (in response to mlybarger)1 of 1 people found this helpfulHi,
AFAIK, I think that the CDI Mixin will inject for you the any CDI Bean into Java Components, but not into the JUnit tests. For this you'll have to use the BeanManager, or Injected TestKit, and then access through there.
Do you want to test the bean, or a Bean Component. If the later, then SwitchYard and SwitchYard's unit testing capabilities are your friend, else, maybe use other JUnit extension that plays with Weld may be better, and if both, again, use SwitchYard's capabilities to test the bean components, and get the bean accessed through the testKit.
Here is a blog post that shows some examples: http://unpoucode.blogspot.se/2014/03/junit-in-switchyard.html
-
2. Re: Unit testing CDI beans
mlybarger Sep 16, 2014 9:38 AM (in response to jorgemoralespou_2)Thanks for the insights! I am looking to test the CDI bean itself. It looks like the CDIMixIn was extended/fixed for sy 2.0 to include the functionality I am interested in.
For my workaround, I created a CDIMixInExt class in my project and pasted the code from the linked CDIMixIn class. I would have preferred to extend CDIMixIn, however the CDIMixIn class is not extensible; the member variables are private.
https://developer.jboss.org/thread/231512