Right, this is for integration testing. I use mocking too, but rarely -- my tests are 80% integration ones and involve DB (the same as in production). For mocks I have to use constructor injection also, and this is the only reason why I use constructor injections. The code looks ugly in this cases, though, when you have more than 5 dependencies per service. And it's also a tedious task when you want to add another dependency to the service, because you have to update all test clients also. That's why I prefer @Inject.
It would be nice to have some api to override, decorate, and advise some services on existing (built) registry instance right in the test method. Maybe (temporarily) replace some service with a mock. So that I won't have to build new module just to override one service for one test case, because it requires additional setup. Just a thoughts. On Tue, Jan 21, 2014 at 9:41 PM, Dragan Sahpaski <dragan.sahpa...@gmail.com>wrote: > 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 > > > -- Dmitry Gusev AnjLab Team http://anjlab.com