On Nov 25, 2013, at 10:00 AM, Cédric Beust ♔ <[email protected]> wrote:

> 
> On Mon, Nov 25, 2013 at 5:51 AM, Brian Pontarelli <[email protected]> 
> wrote:
> Cédric,
> 
> Assuming you don't use setters, how do you test without an injector or hacked 
> up reflection?
> 
> Why would I test without an injector? That's the whole point.
> 
> We test with TestNG (obviously) which supports Guice natively and we use what 
> I believe are fairly common techniques, with a mix of mocks and fake objects 
> and for our functional tests, production modules overridden with test ones.

Personally, I prefer not to unit test with an injector. YMMV.

>  
> field injection does not have the same guarantees from the JVM as 
> constructors.
> 
> I've been trying to get a concrete proof for that last statement (the theory 
> indicates it should take about twenty lines to demonstrate) without much luck 
> so far. I'm still hopeful to get one.

This is part of the language. I’m not sure what proof you need beyond the 
semantics of constructors versus fields. The JVM guarantees that an object and 
its parent objects are constructed and ready for use after the constructor 
finishes. It makes no guarantees for fields, especially if they are accessible 
outside of the object (setters). Inheritance also factors into fields since 
sub-classes can impact the handling of “this.foo” depending on what it and its 
parent define.

— Brian

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to