I usually don't use Guice in small unit tests (1 class tests), but as the unit gets bigger and includes more than a handful of classes it seamed to be a good choice.
The thing is, eventually I saw 2 problems with using it:
-
Run time
setting up the guice injector takes a long time therefore my tests become longer. I'm currently creating the injector in the setup method to start clean in each test.
I tried moving the injector creation to @BeforeClass and it cuts run time by 3. but now I have to take care of cleaning up after each test since there are some singletons.
Is there any other way to make my tests run faster?
Are there any guidelines for managing test with shared state?
-
Managing guice modules
since the intention of this test is to test a whole package, I wanted it to be wired like the production version except for some mocks & fakes that I had to inject for testing.
I tried using Modules.override() but ran into some problems. for instance, not being able to override Just-in-time bindings.
So I ended up writing a separate module for the test, which means I have to change it each time I change the wiring in the production code
Any idea how to solve this?
BTW. We are using Guice version 3.0
Aucun commentaire:
Enregistrer un commentaire