Hi Ashwin,

   - How do you guys make Guice work in JUnit?
      - I looked at various projects like Jukito, Guiceberry but they are
      all way too complex, unnecessary and really do nothing to help
      - Again, it all comes down to being able to start/stop multiple/single
      Injectors
      - Do you just use @Before anno in Junit to start the module once. But
      how do you shut it down for the next test?

There is a 3rd way that relies on a custom Runner for JUnit (See
http://cowwoc.blogspot.com/2008/10/integrating-google-guice-into-junit4.html):
it is much simpler than  Guiceberry, for instance, but also has some
limitations (e.g. how to use it with the @Parameters annotation with it?).

In some ways, I also find JUnit4 adds some complexity (needed?) and tries to
implement it's own DI for things like rules and method hooks to initialize
data (maybe this is indeed the way to go for a DI independent interface?).
For unit tests it is great, but when I try to add more complex harness
around my integration tests I find it lacking (I think that
TestSetup/TestDecorators were great in JUnit3). Consider the case where I am
running tests simulating a cluster. I want to feed my tests with data based
on whether this is in node1, node2, etc scope. @BeforeClass/@AfterClass and
@Before/@After are too limiting for that. I wish was a Guice-based Runner
that would allow me to easily define additional scopes
(clusterwide/singleton, per-node/multithreaded/singlethreaded, per test
class, per test) for test data and simply inject Provider<XXX> into my
tests, support @Parameters with optionally something like Quickcheck/Haskell
and support free injection in the contructor or even test methods.


   - Why isn't there a way to get the Injector from the Guice class? After
   creating the Injector, I had to store a reference to it in a singleton
   class' static field
      - This singleton-for-the-Injector kind of defeated the purpose of the
      whole thing. I was beginning to think that a simple
Registry/Factory of my
      own would've accomplished many of these things

Could you just inject the Injector with @Inject?

@Inject
> private Injector injector;


-- yuri

On Mon, Aug 22, 2011 at 2:14 PM, Ashwin Jayaprakash <
[email protected]> wrote:

> Hi, I've been making an attempt to learn Guice, but these questions kept
> cropping up. Hopefully someone here can provide answers.
>
>
>    - Does constructor injection use reflection all the time or is there an
>    option to switch to bytecode generation?
>    - Is there a way to discard/shutdown the singletons? I saw 
> Issue-62<http://code.google.com/p/google-guice/issues/detail?id=62>and this 
> seems to have been open since 2007 !!
>       - How do you shutdown a module and restart it - example, when it has
>       seen network/DB/JMS errors?
>       - Can multiple Injector instances be created?
>       - This would be useful for running multiple versions of the module
>       in parallel
>       - Or at least for module-level testing, I felt the need for starting
>       the same module with different configurations
>    - How do you guys make Guice work in JUnit?
>       - I looked at various projects like Jukito, Guiceberry but they are
>       all way too complex, unnecessary and really do nothing to help
>       - Again, it all comes down to being able to start/stop
>       multiple/single Injectors
>       - Do you just use @Before anno in Junit to start the module once.
>       But how do you shut it down for the next test?
>    - Why isn't there a way to get the Injector from the Guice class? After
>    creating the Injector, I had to store a reference to it in a singleton
>    class' static field
>       - This singleton-for-the-Injector kind of defeated the purpose of
>       the whole thing. I was beginning to think that a simple 
> Registry/Factory of
>       my own would've accomplished many of these things
>
>
> Thanks,
> Ashwin.
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-guice/-/Z91EearG0MIJ.
> 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