Code coverage with JaCoCo appears not to show lines as partially covered?
Answered
Hi!
When I run code coverage with the JaCoCo engine, I think I get partially covered lines (like if statements) displayed as fully covered. When I run the same test on our CI server, SONAR (using JaCoCo) flags them correctly as partially covered.
Has anyone else experienced the same issue?
Kind regards,
Christian
Please sign in to leave a comment.
Hello,
I'm facing same issue but I'm still searching…
It would be great to have any explanation...! :D
Regards,
Sylvain
please create a ticket here https://youtrack.jetbrains.com/issues/IDEA and provide a sample project so we can take a look at it from our side, thank you!
Hello,
I've made a simple test and I reproduce my weird case with
JACOCO
:I just don't know why this is happening because we can see in the screen shot that the tested service
ThrowService
is fully covered, but not the actuel JUnit test methodthrowServiceTest
…- Do I get rid of the JUnit package when launching the Code Coverage with Jacoco ?
- Is something that I'm doing wrong ?
I'm using :
JAVA : jdk-11.0.20
SPRING :
org.springframework.boot:spring-boot-starter-test:2.7.16
org.junit.jupiter:junit-jupiter-engine:5.8.2
org.junit.platform:junit-platform-launcher:1.8.2
org.junit.vintage:junit-vintage-engine5.8.2
…and Intellij :
IntelliJ IDEA 2023.2.4 (Ultimate Edition)
Build #IU-232.10203.10, built on October 24, 2023
Runtime version: 17.0.8.1+7-b1000.32 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 3996M
Cores: 16
Registry:
ide.experimental.ui=true
Kotlin: 232-1.9.0-IJ10203.10
Here is the code :
@Slf4j
@ExtendWith(MockitoExtension.class)
class ThrowServiceTest {
@InjectMocks
private ThrowService throwService;
@Test
void throwServiceTest() {
Assertions.assertThatExceptionOfType(UnsupportedOperationException.class)
.isThrownBy(() ->
throwService.throwException()
)
.withNoCause();
}
}
And the service :
@Slf4j
@Service
public class ThrowService {
public void throwException() {
throw new UnsupportedOperationException("Some message...");
}
}
EDIT : Ok, I'm sorry for that ! :D
Sylvainsa Hello! Please try the latest IDEA version 2023.3.
The service itself looks actually fully covered, while you shared with us the coverage of the test class. The numbers show 6/7 lines covered, so we see one line as uncovered.
Note: you can disable coverage in test folders with ‘Enable coverage in test folders’ option: https://www.jetbrains.com/help/idea/running-test-with-coverage.html#coverage-run-configurations
For further investigation, could you please generate an HTML report and share a screenshot of it https://www.jetbrains.com/help/idea/generating-code-coverage-report.html ?