Does JaCoCo work with mocking frameworks?

1,627 views
Skip to first unread message

eaudec...@gmail.com

unread,
Oct 4, 2017, 9:37:51 PM10/4/17
to JaCoCo and EclEmma Users
I've banging my head against the wall trying to make JaCoCo include coverage for tests that use Mockito. I'm writing unit & instrumentation test for Android and JaCoCo keep yielding 0% code coverage for the tests that use Mockito to mock objects.

Can someone please confirm if JaCoCo works with Mockito?

I have a question in SO with all the details, so please feel free to take a look https://stackoverflow.com/questions/46517471/jacoco-mockito-android-tests-zero-coverage-reported

Cheers!

Henrik Horneber

unread,
Oct 4, 2017, 10:58:48 PM10/4/17
to jac...@googlegroups.com
I think we had jacoco test coverage running for tests that used mocking at some point. As long as you don't mock the class-under-test, I don't see a reason why it should not work. I faintly remember some byte code manipulation issues, but I'm probably mixing up aspectJ and mock frameworks here.

Hope this helps. 

--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/d558e2cc-6697-47eb-a1f2-59dd4905325d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mirko Friedenhagen

unread,
Oct 5, 2017, 1:01:27 AM10/5/17
to jac...@googlegroups.com
Hello,  at my company we use jacoco with mockito all the time, power-mockito or any framework which manipulates the classes when loading them is more tricky.

Regards
Mirko
--
Sent from my mobile

Am 05.10.2017 03:37 schrieb <eaudec...@gmail.com>:

eaudec...@gmail.com

unread,
Oct 5, 2017, 1:09:29 AM10/5/17
to JaCoCo and EclEmma Users
On Wednesday, 4 October 2017 19:58:48 UTC-7, Henrik Horneber wrote:
> I think we had jacoco test coverage running for tests that used mocking at some point. As long as you don't mock the class-under-test, I don't see a reason why it should not work. I faintly remember some byte code manipulation issues, but I'm probably mixing up aspectJ and mock frameworks here.
>
>
> Hope this helps. 
>
>
> Am 05.10.2017 03:37 schrieb <eaudec...@gmail.com>:
> I've banging my head against the wall trying to make JaCoCo include coverage for tests that use Mockito. I'm writing unit & instrumentation test for Android and JaCoCo keep yielding 0% code coverage for the tests that use Mockito to mock objects.
>
>
>
> Can someone please confirm if JaCoCo works with Mockito?
>
>
>
> I have a question in SO with all the details, so please feel free to take a look https://stackoverflow.com/questions/46517471/jacoco-mockito-android-tests-zero-coverage-reported
>
>
>
> Cheers!
>
>
>
> --
>
> You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
>
> To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
I do need to mock some methods of classes under test. Do you think that's something JaCoCo won't cover?

eaudec...@gmail.com

unread,
Oct 5, 2017, 1:11:09 AM10/5/17
to JaCoCo and EclEmma Users
On Wednesday, 4 October 2017 22:01:27 UTC-7, Mirko Friedenhagen wrote:
> Hello,  at my company we use jacoco with mockito all the time, power-mockito or any framework which manipulates the classes when loading them is more tricky.
>
>
> Regards
> Mirko
> --
> Sent from my mobile
>
>
> Am 05.10.2017 03:37 schrieb <eaudec...@gmail.com>:
> I've banging my head against the wall trying to make JaCoCo include coverage for tests that use Mockito. I'm writing unit & instrumentation test for Android and JaCoCo keep yielding 0% code coverage for the tests that use Mockito to mock objects.
>
>
>
> Can someone please confirm if JaCoCo works with Mockito?
>
>
>
> I have a question in SO with all the details, so please feel free to take a look https://stackoverflow.com/questions/46517471/jacoco-mockito-android-tests-zero-coverage-reported
>
>
>
> Cheers!
>
>
>
> --
>
> You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
>
> To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
I know you can't release the secret sauce that you use in your company to use jacoco + mockito, but it'd be great if you can point me in the right directions. Maybe some tutorial or similar resource that might help me to get this working. I've searched for days and haven't been able to make it work.

Evgeny Mandrikov

unread,
Oct 6, 2017, 5:48:20 PM10/6/17
to JaCoCo and EclEmma Users


On Thursday, October 5, 2017 at 7:11:09 AM UTC+2, eaudec...@gmail.com wrote:
I know you can't release the secret sauce that you use in your company to use jacoco + mockito, but it'd be great if you can point me in the right directions. Maybe some tutorial or similar resource that might help me to get this working. I've searched for days and haven't been able to make it work.

There is no secret source - it works as expected, but your understanding/usage/expectations about mocking is wrong as answered in https://stackoverflow.com/a/46614216/244993

Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages