Discussion:
Guice + Mockito
David Nouls
2018-06-08 06:33:35 UTC
Permalink
Never tried Jukito ? works great.
5 years late to the party. I ended up implementing my own library at my current company: https://eng.collectivehealth.com/introducing-testmodule-bdab286f12db.
How can I mock injected dependencies in JUnit tests? Thanks.
        Collective Health introduces the Employer-Driven Healthcare Economy
This message may contain confidential, proprietary, or protected information.  If you are not the intended recipient, you may not review, copy, or distribute this message. If you received this message in error, please notify the sender by reply email and delete this message.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/ad0848e7-a545-4214-a4af-b174a5106b2f%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+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/a8be4b08-1bc2-4bdf-9ef3-397856d1ef59%40Spark.
For more options, visit https://groups.google.com/d/optout.
yu via google-guice
2018-06-08 07:46:27 UTC
Permalink
The problem seemed simple enough, so I didn't bother looking for an
existing solution. It took less than a day and two iterations to get
everything I needed into the custom library. Of course, it took a lot
longer to make it look prettier. :)
Post by David Nouls
Never tried Jukito ? works great.
On 8 Jun 2018, 00:55 +0200, yu via google-guice <
5 years late to the party. I ended up implementing my own library at my
https://eng.collectivehealth.com/introducing-testmodule-bdab286f12db.
How can I mock injected dependencies in JUnit tests? Thanks.
Collective Health introduces the Employer-Driven Healthcare
Economy <https://collectivehealth.com/our-mission/>
*This message may contain confidential, proprietary, or protected
information. If you are not the intended recipient, you may not review,
copy, or distribute this message. If you received this message in error,
please notify the sender by reply email and delete this message.*
--
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
<javascript:>.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/ad0848e7-a545-4214-a4af-b174a5106b2f%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/ad0848e7-a545-4214-a4af-b174a5106b2f%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
        Collective Health introduces the Employer-Driven Healthcare
Economy <https://collectivehealth.com/our-mission/>



_This message may
contain confidential, proprietary, or protected information.  If you are
not the intended recipient, you may not review, copy, or distribute this
message. If you received this message in error, please notify the sender by
reply email and delete this message._
--
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.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/e8380991-a1d2-4ec6-b407-533440452d6f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
David Nouls
2018-06-08 07:53:05 UTC
Permalink
I had something similar implemented a few years ago. Indeed not difficult to do.

But I switched to Jukito because it offers a few advanced features:
- Interfaces and abstract classes are automatically mocked (as a singleton). In many cases you don’t need to define any binding if you use interfaces for your injected dependencies.
- you can have parameters on your test methods and these parameters are automatically injected. This can even work on @Before methods.
- Uses annotations to provide the modules to use (that would allow defining your own bindings).

Groeten,
David
The problem seemed simple enough, so I didn't bother looking for an existing solution. It took less than a day and two iterations to get everything I needed into the custom library. Of course, it took a lot longer to make it look prettier. :)
Post by David Nouls
Never tried Jukito ? works great.
5 years late to the party. I ended up implementing my own library at my current company: https://eng.collectivehealth.com/introducing-testmodule-bdab286f12db.
How can I mock injected dependencies in JUnit tests? Thanks.
        Collective Health introduces the Employer-Driven Healthcare Economy
This message may contain confidential, proprietary, or protected information.  If you are not the intended recipient, you may not review, copy, or distribute this message. If you received this message in error, please notify the sender by reply email and delete this message.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/ad0848e7-a545-4214-a4af-b174a5106b2f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
        Collective Health introduces the Employer-Driven Healthcare Economy
This message may contain confidential, proprietary, or protected information.  If you are not the intended recipient, you may not review, copy, or distribute this message. If you received this message in error, please notify the sender by reply email and delete this message.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/e8380991-a1d2-4ec6-b407-533440452d6f%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+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/9e7c6e19-3ea5-47bb-9e96-02d89648efe9%40Spark.
For more options, visit https://groups.google.com/d/optout.
yu via google-guice
2018-06-08 16:24:47 UTC
Permalink
Thank you for the suggestion, I'll take a look at it.
Post by David Nouls
I had something similar implemented a few years ago. Indeed not difficult to do.
- Interfaces and abstract classes are automatically mocked (as a
singleton). In many cases you don’t need to define any binding if you use
interfaces for your injected dependencies.
- you can have parameters on your test methods and these parameters are
- Uses annotations to provide the modules to use (that would allow
defining your own bindings).
Groeten,
David
On 8 Jun 2018, 09:46 +0200, yu via google-guice <
The problem seemed simple enough, so I didn't bother looking for an
existing solution. It took less than a day and two iterations to get
everything I needed into the custom library. Of course, it took a lot
longer to make it look prettier. :)
Post by David Nouls
Never tried Jukito ? works great.
On 8 Jun 2018, 00:55 +0200, yu via google-guice <
5 years late to the party. I ended up implementing my own library at my
https://eng.collectivehealth.com/introducing-testmodule-bdab286f12db.
How can I mock injected dependencies in JUnit tests? Thanks.
Collective Health introduces the Employer-Driven Healthcare
Economy <https://collectivehealth.com/our-mission/>
*This message may contain confidential, proprietary, or protected
information. If you are not the intended recipient, you may not review,
copy, or distribute this message. If you received this message in error,
please notify the sender by reply email and delete this message.*
--
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
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/ad0848e7-a545-4214-a4af-b174a5106b2f%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/ad0848e7-a545-4214-a4af-b174a5106b2f%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
Collective Health introduces the Employer-Driven Healthcare
Economy <https://collectivehealth.com/our-mission/>
*This message may contain confidential, proprietary, or protected
information. If you are not the intended recipient, you may not review,
copy, or distribute this message. If you received this message in error,
please notify the sender by reply email and delete this message.*
--
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
<javascript:>.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/e8380991-a1d2-4ec6-b407-533440452d6f%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/e8380991-a1d2-4ec6-b407-533440452d6f%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
        Collective Health introduces the Employer-Driven Healthcare
Economy <https://collectivehealth.com/our-mission/>



_This message may
contain confidential, proprietary, or protected information.  If you are
not the intended recipient, you may not review, copy, or distribute this
message. If you received this message in error, please notify the sender by
reply email and delete this message._
--
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.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/1e2ec675-18df-4c7a-bd89-25490675bbb6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...