Best JUnit/Guice/Mockito integration library?

1,726 views
Skip to first unread message

Thomas Johnson

unread,
Feb 21, 2011, 10:52:17 AM2/21/11
to google-guice
What's the most matures/ library for combining Guice, JUnit, and
Mockito for testing? I've seen guiceberry, Jukito, mycila, atunit...

There seem to be some libraries that have support for Guice 2, and a
few that have support for Guice 3, and none are terribly well-
documented.

Esko Luontola

unread,
Feb 21, 2011, 1:20:43 PM2/21/11
to google-guice
On Feb 21, 5:52 pm, Thomas Johnson <thomas.j.john...@gmail.com> wrote:
> What's the most matures/ library for combining Guice, JUnit, and
> Mockito for testing?

All of those as-is. Constructing a Guice injector is only a couple of
lines of code, so why would a library be needed for it? On the other
hand, a large test setup is a code smell that there is some problem
with the design. Even depending on Guice or some other DI library in
unit-level tests is a code smell.

Thomas Johnson

unread,
Feb 21, 2011, 1:24:42 PM2/21/11
to google...@googlegroups.com
I think it's mostly for the module setup. If I've got a class that takes a half-dozen dependencies in its constructor, don't I have to write a test module that binds all its dependencies to the corresponding mock objects?

Christian Goudreau

unread,
Feb 21, 2011, 1:27:35 PM2/21/11
to google...@googlegroups.com
http://code.google.com/p/jukito/

Even depending on Guice or some other DI library in unit-level tests is a code smell.
It's not about depending on Guice, it's about productivity. Any test could be written without the need for Guice, but it's more work. If you're using Guice at every level of your app, why not using it in your test ? It's well documented, well tested and easy to use.

Jukito works with Guice 3 even if it's not written. There's not a lot of documentation but it's because there's almost no boiler plate to write ! Jukito use standard Guice annotation and allow you to inject in any JUnit method anything you want. It will also automatically mock any interface it find that you didn't binded inside you test module.

Btw, if you need anything else on Jukito, more documentation, just ask, we will do it ! Here's an interesting blog post about how to test views with JUnit and Jukito:

Cheers, 


--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To post to this group, send email to google...@googlegroups.com.
To unsubscribe from this group, send email to google-guice...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.




--
Christian Goudreau

Christian Goudreau

unread,
Feb 21, 2011, 1:30:53 PM2/21/11
to google...@googlegroups.com
One thing that I didn't mentioned:
If a class isn't binded as mock inside the module, Jukito will try to instantiate it like Guice would. 

Cheers,
--
Christian Goudreau

Nate Pendleton

unread,
Aug 7, 2013, 4:52:10 PM8/7/13
to google...@googlegroups.com
Jukito seemed quite nice, but I could not integrate it with Maven/Tycho. Something to be aware of.

Laszlo Ferenczi

unread,
Aug 9, 2013, 3:40:34 AM8/9/13
to google...@googlegroups.com
We ended up rolling our own, a simple JUnit runner implementation which creates the injector before every test. The modules are specified in an annotation on the class level in each test class.

HTH

--
L


--
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...@googlegroups.com.

To post to this group, send email to google...@googlegroups.com.

Vadim Bondarev

unread,
Aug 10, 2013, 3:15:00 AM8/10/13
to google...@googlegroups.com


Please take a look on this project 

Tim Boudreau

unread,
Aug 27, 2013, 8:16:31 PM8/27/13
to google...@googlegroups.com
Here is a Guice-based test-runner I wrote and have been using for years in many projects:
https://github.com/timboudreau/giulius-selenium-tests

An example is probably worth two paragraphs of description:

@RunWith(GuiceTest.class)
public class MyTest {

    @TestWith(MyModule.class)
    public void test(ThingToTest injected) { ... }
}

Tthe TestWith annotation can also be on the class, and there is an advanced feature of being able to iterate a set of different modules - say, different implementations of the same basic thing - and run the test with each one, or even with all possible combinations of two lists of modules.  And there are provisions for auto-binding the contents of properties files.

-Tim

Reply all
Reply to author
Forward
0 new messages