A sample project showcase of how to merge the coverage data from both androidTest
and test
.
=============
Blog Post (en-US) Another Blog Post (en-US)
Blog Post (pt-BR)
Mixing the coverage data from both Instrumented and Unit tests
License: Apache License 2.0
A sample project showcase of how to merge the coverage data from both androidTest
and test
.
=============
Blog Post (en-US) Another Blog Post (en-US)
Blog Post (pt-BR)
Great guide and examples! Thank you!
I think the example can benefit from adding multiple flavors, or at least some comments related to them. Unfortunately, jacoco does not provide any error messages if folders with execution data are empty or non-existent. This will be the case if a multi-flavor app is tested. Some adjustments are required to the paths:
val javaClasses = fileTree("dir" to "$buildDir/intermediates/javac/developDebug", "excludes" to fileFilter)
val kotlinClasses = fileTree("dir" to "$buildDir/tmp/kotlin-classes/developDebug", "excludes" to fileFilter)
val mainSrc = "$projectDir/src/main/java"
sourceDirectories.setFrom(files(listOf(mainSrc)))
classDirectories.setFrom(files(listOf(javaClasses, kotlinClasses)))
executionData.setFrom(fileTree(
"dir" to project.buildDir,
"includes" to listOf(
"jacoco/testDevelopDebugUnitTest.exec",
"outputs/code_coverage/developDebugAndroidTest/connected/**/*.ec"
)
))
When adding task in build.gradle and syncing, Im getting below error:
A problem occurred evaluating project ':app'.
> Cannot set the value of read-only property 'sourceDirectories' for task ':app:jacocoTestReport' of type org.gradle.testing.jacoco.tasks.JacocoReport.
What im doing wrong ?
Unknown Execution value 'ANDROIDX_TEST_ORCHESTRATOR'. Possible values are 'host', 'android_test_orchestrator'.
Open File
Task :app:connectedDebugAndroidTest
Starting 0 tests on SM-J700F - 6.0.1
com.android.builder.testing.ConnectedDevice > No tests found.[SM-J700F - 6.0.1] FAILED
No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @test annotations).
Task :app:connectedDebugAndroidTest FAILED
FAILURE: Build failed with an exception.
There were failing tests. See the report at: file:///D:/Satsuma/AAA_Sample/QA/unified-code-coverage-android-master/app/build/reports/androidTests/connected/index.html
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 55s
52 actionable tasks: 1 executed, 51 up-to-date
1:15:09 PM: Task execution finished 'createDebugCoverageReport'.
Hi,
I tried out the sample, it works perfectly fine. Thing doesn't work as expected when I added a new file.
I added a file UnitTestSample in main/java/src.
`public class UnitTestSample {
public static int add(int i, int j){
return i+j;
}
}`
and a UnitTest file in test/java/src
public class UnitTest { @Test public void testAdd(){ assertEquals(2,UnitTestSample.add(1,1)); } }
What I expected from the coverage report is that it should shows 2 classes, MainActivity & UnitTestSample under package net.rafaeltoledo.coverage but it shows only MainActivity. The coverage report is at app/build/reports/jacoco/jacocoTestReport/html/index.html.
Is there anything I missed out?
Noticed that coverage only works for Robolectric unit test, but not for instrumentation MainActivityTest
with ActivityTestRule
. So if I remove MainActivityUnitTest
coverages goes to 0%, but MainActivityTest
is still running. Is it limitation of jacoco/report or I miss something?
why branch coverage is n/a
As of now, if any test fails, Jacoco doesn't generate the code coverage report in percentage. Can we generate a test coverage report even if any test fails?
Let's say we have 5 instrumentation test cases, and only one of them is failing. But 4 of them are successfully executed. Can we check, how much code is covered by 4 passed tests ignoring 1 failed test?
After running ./gradlew createDebugCoverageReport
task and opening report (app/build/reports/coverage/debug/index.html
) I can see in the right bottom corner this text version:
Created with JaCoCo 0.7.9.201702052155
Shouldn't the JaCoCo version be the same as version defined in ext.jacocoVersion
๐ค
Ive cloned the repo and run ./gradlew clean jacocoTestReport
and the resulting app/build/reports/coverage/debug/net.rafaeltoledo.coverage/index.html
report says 0% test coverage
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.