On Mon, Aug 24, 2009 at 5:07 AM, Max Bowsher<[email protected]> wrote:
> Rick wrote:
>
>> but how do I set it up so that my
>> Provider isn't run repeatedly during the tests?
>
> Bind the provider in singleton scope. Either by annotating your provider
> class @Singleton or calling bind(MyProvider.class).in(Singleton.class);
>

This will indeed ensure that your provider is created only once across
test methods, but *only* if you don't recreate the Guice injector
between each test.  Recreating the injector establishes a new
Singleton scope instance.

This surfaces a testing philosophy issue to think about - how paranoid
do you want to be about the execution of one test having potential
side effects that change the behavior of subsequently executed tests?
I tend to be on the "throw away everything" side of this, so I do
indeed recreate the injector (and therefore all my singleton scope
resources) in the setup method when I am testing a Guice based
application.  If the resources your provider creates are immutable,
you might not care so much about this.

Or, you might want to have some sort of switch so that you can do the
"recreate the injector" trick during a continuous integration build,
but not take the extra time when the developer is running tests
locally.

Craig McClanahan

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