question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"mock-maker-inline" prevents collection of code coverage for spys

See original GitHub issue

Hi,

Being one of JaCoCo (Java Code Coverage Library) developers, I was curious about interoperability of Mockito 2.2.x and JaCoCo on-the-fly instrumentation (using agent), so did some tests and came across following behavior:

with mock-maker-inline: mock-maker-inline without: normal

Here is small example that reproduces this behavior - example.zip , mvn clean verify to run tests and generate JaCoCo report.

  • Mockito 2.2.16
  • JaCoCo 0.7.7
  • JDK 8u102

As a workaround possible to use JaCoCo offline instrumentation (mvn clean verify -Djacoco-offline on the given example), but we don’t recommend this mode and it is not available nor in EclEmma (plugin for Eclipse based on JaCoCo), nor when using JaCoCo in IntellIJ IDEA.

Also should be noted that the same happens for IntelliJ IDEA’s own built-in coverage engine:

intellij-mock-maker-inline vs intellij-normal

Unfortunately, I didn’t had time (yet) to dig deeper into code of Mockito to understand why this happens. Best guess based on investigation of similar issue with PowerMock: Mockito’s agent bypasses other agents by reading class files from disk.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:23 (12 by maintainers)

github_iconTop GitHub Comments

6reactions
SPYcommented, Nov 15, 2016

I’ve never used java and mockito, but I read the issues here so often(due to mentioning). Maybe I should start contribute here.

2reactions
TimvdLippecommented, Nov 15, 2016

Issue opened and closed within 6 hours. New record? 🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to mock a final class with mockito - java - Stack Overflow
I was using Powermock for mocking final classes and static methods to increase my coverage that was officially checked on Sonarqube . Coverage...
Read more >
How to use the Mockito's inline mock maker - David Vlijmincx
Keep this code in a try with resources to limit the scope, so you only mock the constructor in that test method.
Read more >
Mocking Private, Static and Void Methods Using Mockito
If the need arises to mock private and static methods/classes, it indicates poorly refactored code and is not really a testable code and...
Read more >
Measuring code coverage - Testing Angular
Code coverage, also called test coverage, tells you which parts of your code are executed by running the unit and integration tests.
Read more >
The Hitchhiker's Guide to Testing Spring Boot APIs and ...
Add Unit Tests for Your Spring Boot Controllers; Mock Okta's API with ... Continuous Integration with Travis CI; Add Code Coverage Reports.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found