I agree with Dimitry but thats more for integration like testing.
For basic unit testing of services methods (usually we unit test a single
method per test) we mock the dependencies (the injected services) and pass
the mocks through the constructor of the service implementation class under
test. That's why we prefer constructor based injection.

If we need to mock methods in the service that's being bested than we
usually use Spy in Spock or the equivalent feature in other mock frameworks.

Cheers,
Dragan Sahpaski


On Tue, Jan 21, 2014 at 6:34 PM, Dmitry Gusev <dmitry.gu...@gmail.com>wrote:

> I usually create base class where I construct registry instance, then I use
> registry.getService(Intf.class) when I need an instance of a service.
>
> Like here:
>
> https://github.com/anjlab/anjlab-tapestry-commons/blob/master/anjlab-tapestry-quartz/src/test/java/com/anjlab/tapestry5/services/quartz/SchedulerTest.java
>
>
> On Tue, Jan 21, 2014 at 9:07 PM, George Christman
> <gchrist...@cardaddy.com>wrote:
>
> > Hello, we are trying to unit test our services, but our services contain
> > other injected services. I'm wondering how you test injected services. Is
> > there a configuration I'm missing?
> >
> > --
> > George Christman
> > www.CarDaddy.com
> > P.O. Box 735
> > Johnstown, New York
> >
>
>
>
> --
> Dmitry Gusev
>
> AnjLab Team
> http://anjlab.com
>

Reply via email to