If you pass dependencies in you constructor which are not required for the test then your class has most likely too many responsibilities.
If all your dependencies are required for the test you have to adapt the test any ways and should not worry about the compiler errors but embrace them since they help you find all the test cases which need update.

I would still say it is best practice to have unit tests (not integration tests) avoid the usage of an injector.

If you want to use the guice injector in the tests I would recommend to use a testing framework like jukito.




On 08/21/2014 12:45 PM, Maatary Okouya wrote:
Hi,


I'd like to be able to insert some mocks in the creation of some of my service for test purpose. Based on the following answer http://stackoverflow.com/questions/483087/overriding-binding-in-guice/531110#531110  on stackOverflow i have the following question:




>>>but if you're writing unit tests, you probably shouldn't be using an injector and rather be injecting mock or fake objects by hand.>>> 

I do not understand that. The all idea of encapsulating creation is to keep it in one place (obviously separating usage from construction). If one inject by hand rather than by an injector, then if the constructor change you have a problem, you need to propagate that in all the test classes that do the creation by hand. Moreover if the constructor are made private as per the best practice recommended, that cause a problem too

Hence, my question here is what is the recommended approach to provide some mock in unit, that do not break the encapsulation of the creation. I do not keep test in the same package as the class. I do BDD. In my test i package by Feature. 


Best,

M
--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/b17f12f0-e141-49d4-850c-6d59630f4f1c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/53F5E918.6090205%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.

Reply via email to