Do no use Guice in the tests. It's better to instantiate the SUT (system under test) manually, so you can use whatever test doubles the test needs. Testing you example code would be something like this if using Mockito:
MyInterfaceA a = mock(MyInterfaceA.class); MyInterfaceB b = mock(MyInterfaceB.class); MyInterfaceC c = mock(MyInterfaceC.class); MyGuiceApp app = new MyGuiceApp(a, b, c, "input.file"); If you need Guice to wire the tests together, then it's a code smell that the system components are too coupled to be tested in isolation. Also on my CPU it takes about 5 ms to instantiate the Injector with a couple of modules (assuming all classes have already been loaded), so it makes the tests considerably slower than simple unit tests which take less than 1 ms. If you need to write end-to-end integration tests, being aware of all the negative sides of integration tests (http://www.infoq.com/ presentations/integration-tests-scam), then using Guice in the tests makes sense. -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
