Code coverage for applications

Answered

https://www.jetbrains.com/help/idea/code-coverage.html

"Measuring code coverage is available for testing, applications, and application server run/debug configurations"

I wish to get coverage information from running and externally testing the application - NOT from unit tests. 

I have configured a Java Spring Boot configuration with code coverage

In the console when it's launched i see

---- IntelliJ IDEA coverage runner ----
tracing and tracking per test coverage ...
include patterns:
au\.com\.greater\..*
exclude patterns:

I then stop the application, and the coverage window is launched.

I think i've tried every combination of sampling, tracing, and the three coverage runners.

I have tried with wildcards for packages, and distinct classes. 

All runs say 0% coverage. 

The only way i CAN get coverage is if i insert a system.exit(0) call, possibly as per 

https://intellij-support.jetbrains.com/hc/en-us/community/posts/206322559-Code-Coverage-Data?input_string=Code%20coverage%20for%20applications

Is this a known issue ? Or am i doing something wrong ?

 

 

0
5 comments

What IDE version do you use? What JDK do you use? Are you sure the class is located under the au.com.greater package and it's methods are executed? E.g. I see the status line in Coverage tool window displays the package 'controller'. Also please check do you see the coverage data in Editor (in the left gutter). Are there any errors in log?

If issue remains, could you provide a sample project (for me it works fine)? Thanks.

0
Avatar
Permanently deleted user

The key point to me is that when i insert the system.exit(0) i DO get the coverage data, and the coverage data lines in the gutter i.e I change ONLY this and i go from not getting the data to getting the data. 

 

IntelliJ IDEA 2018.1.5 (Ultimate Edition)
Build #IU-181.5281.24, built on June 12, 2018
Licensed to *****

JRE: 1.8.0_152-release-1136-b39 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 7 6.1

Answers to your questions

- Yes the class is located under au.com.greater

- Yes the method is executed. I run the same external calls with the program running under the debugger and i hit breakpoints in this location

- I don't see any coverage data in the gutter. 

- Checking the log file i see an error, but only related to when i try the jacoco coverage runner 

java.io.IOException: Error while analyzing C:\dev2\######\TestConfiguration.class.
    at org.jacoco.core.analysis.Analyzer.analyzerError(Analyzer.java:155)
    at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:130)
    at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:147)
    at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:185)
    at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:218)
    at com.intellij.coverage.JaCoCoCoverageRunner$2.visitFile(JaCoCoCoverageRunner.java:112)
    at com.intellij.coverage.JaCoCoCoverageRunner$2.visitFile(JaCoCoCoverageRunner.java:107)
    at java.nio.file.Files.walkFileTree(Files.java:2670)
    at java.nio.file.Files.walkFileTree(Files.java:2742)
    at com.intellij.coverage.JaCoCoCoverageRunner.loadExecutionData(JaCoCoCoverageRunner.java:107)
    at com.intellij.coverage.JaCoCoCoverageRunner.loadCoverageData(JaCoCoCoverageRunner.java:52)
    at com.intellij.coverage.BaseCoverageSuite.loadProjectInfo(BaseCoverageSuite.java:245)
    at com.intellij.coverage.JavaCoverageSuite.getCoverageData(JavaCoverageSuite.java:177)
    at com.intellij.coverage.CoverageSuitesBundle.getCoverageData(CoverageSuitesBundle.java:95)
    at com.intellij.coverage.PackageAnnotator.annotate(PackageAnnotator.java:140)
    at com.intellij.coverage.JavaCoverageAnnotator.lambda$createRenewRequest$1(JavaCoverageAnnotator.java:142)
    at com.intellij.coverage.BaseCoverageAnnotator$1.run(BaseCoverageAnnotator.java:36)
    at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:750)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$1(CoreProgressManager.java:157)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:580)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:525)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:85)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:144)
    at com.intellij.openapi.progress.impl.CoreProgressManager$4.run(CoreProgressManager.java:395)
    at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:305)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: Can't add different class with same name: au/com/greater/test/******/query/TestConfiguration
    at org.jacoco.core.analysis.CoverageBuilder.visitCoverage(CoverageBuilder.java:107)
    at org.jacoco.core.analysis.Analyzer$1.visitEnd(Analyzer.java:96)
    at org.jacoco.asm.ClassVisitor.visitEnd(ClassVisitor.java:317)
    at org.jacoco.core.internal.flow.ClassProbesAdapter.visitEnd(ClassProbesAdapter.java:98)
    at org.jacoco.asm.ClassReader.accept(ClassReader.java:712)
    at org.jacoco.asm.ClassReader.accept(ClassReader.java:521)
    at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:111)
    at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:127)
    ... 28 more

I'll investigate this error more. 

To be clear - could you please confirm that you get this coverage data NOT when running tests, but when simply when running the application with coverage ? I suspect this to be the case, but want to be sure. 

0

The first time I tried to reproduce - the Spring Boot Application exited by itself, so there was code coverage. When I launch and use 'Stop' button - I also see not coverage. Created the https://youtrack.jetbrains.com/issue/IDEA-195386 to investigate. Please follow it for updates. Thanks.

0
Avatar
Permanently deleted user

Thanks Andrey, much appreciated. 

I didn't see your comment around a test project. I'm assuming since you've been able to reproduce it that's no longer necessary ?

And I should have been clearer. My application is a service, so it doesn't terminate, i stop it using the 'stop' button in the IDE i.e the same as you outlined above when you reproduced the issue. 

This may turn out to be a limitation of whatever is collecting the coverage data - i've seen mention in the jacoco documentation of an agent (i'm not a java guru so i'm not familiar with the internals of how it might collect coverage data) - so if it turns out that it's difficult to resolve then calling out the workaround of exiting the process in the documentation would be sufficient. 

 

 

0

Yes I've reproduced it on Windows. On OS X it worked for me (coverage showed after pressing 'Stop').

Thanks for details. You may follow the https://youtrack.jetbrains.com/issue/IDEA-195386 for further progress.

0

Please sign in to leave a comment.