What's your ultimate goal in testing the module?

Modules should have no logic in them, and ideally should require no
specific tests.  All a Module does is setup your object graph, so the best
"test" of your app's whole Module is with integration tests of your app.
 If you want to ensure a subcomponent's Module is wiring things up
correctly, then again I'd suggest the best thing is an integration test of
that subcomponent.

sam

On Sun, Jan 29, 2012 at 4:59 PM, egolan <[email protected]> wrote:

> I have finally created my first module in our big scale application.
> It's clean, readable and cool :)
>
> My next step was to test it (in the following modules I will try to
> 'test first').
> So I created a Test class.
> Created a TestModule that extends AbstractModule and installs my own
> module (I did it like that, as my module is dependent on modules that
> injected separately).
>
> In the test I called to the injector and verified that instances are
> not null, in Singleton I verifies sameInstance.
>
> Is there a best approach to test the module?
>
> Here's part of the test:
>
>    @SuppressWarnings("unchecked")
>    @Test
>    public void shouldConstructObjects() {
>        final Properties properties = new Properties();
>        properties.setProperty("MpsQueryFilter", "1=1");
>        // more properties here...
>
>        final MpsOperations mpsOperations =
> mock(MpsOperations.class);// created in a different module
>        final IDataCollector dataCollector =
> mock(IDataCollector.class); // created in a different module
>        final RecordsCounterOperations recordsCounterOperations =
> mock(RecordsCounterOperations.class); // created in a different module
>
>        Module testModule = new AbstractModule() {
>
>            @Override
>            protected void configure() {
>                Names.bindProperties(binder(), properties);
>                bind(MpsOperations.class).toInstance(mpsOperations);//
> created in a different module
>                bind(new TypeLiteral<IDataCollector<CoreMpsData>>()
> {}).toInstance(dataCollector);// created in a different module
>
>
> bind(RecordsCounterOperations.class).toInstance(recordsCounterOperations);//
> created in a different module
>
>                install(new MpsLogicModule()); // This is the actual
> module to be tested
>            }
>        };
>
>        Injector injector = Guice.createInjector(testModule);
>
>        MpsProcessor mpsProcessor1 =
> injector.getInstance(MpsProcessor.class);
>        MpsProcessor mpsProcessor2 =
> injector.getInstance(MpsProcessor.class);
>        assertNotNull(mpsProcessor1);
>        assertSame(mpsProcessor1, mpsProcessor2);//checking singleton
>
>        ManagerStrategy managerStrategy1 =
> injector.getInstance(ManagerStrategy.class);
>        ManagerStrategy managerStrategy2 =
> injector.getInstance(ManagerStrategy.class);
>        assertNotNull(managerStrategy1);
>        assertSame(managerStrategy1, managerStrategy2);
>
> .... // more asserts here...
> }
>
> --
> 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.
>
>

-- 
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.

Reply via email to