-
1. Re: How to inject mocks in an Arquillian test?
bmajsak Nov 8, 2012 2:26 PM (in response to smikloso)1 of 1 people found this helpfulI think this should help you to some extent https://github.com/arquillian/arquillian-showcase/tree/master/extensions/autodiscover
With regards to injecting mocked dao to the service - how about using @Inject instead of @EJB and write your own CDI producer (could be within the test class itself) which will create such a mocked repository?
As a side note I'm not really conviced if you really need mocks if you already have concrete implementations for your services and DAOs. This should be more for unit testing rather than integration testing where you anyway use container's infrastructure.
Hope that helps.
Cheers,
Bartosz
-
2. Re: How to inject mocks in an Arquillian test?
michaelyaakoby Nov 1, 2013 7:36 PM (in response to bmajsak)Personally, I rather tests my EJBs as "units" before I get into integration-tests such that are enabled by Arquillian.
Usually I mock all the dependencies of my EJB thus making it a real unit-test.
This is why I've created testfun-JEE which allows you to inject EJBs directly into your test class and it doesn't require any container.
testfun-JEE supports injection of EJBs, entity manager and some other common resources (such asJ DBC data source and context) - dependencies in injected EJBs are also being taken care by testfun-JEE.
One of the cool features of testfun-JEE is that if you add a variable member, which is an interface of an EJB, to your test class and this variable is annotated with @Mock (from Mockito), than this mock will replace the EJB everywhere.
See examples in https://github.com/michaelyaakoby/testfun