Hi,

I am using Kotlin objects to define constants in my project. When I am 
using these constants in any class, the coverage of that class becomes 0.

*object Constant {*
* const val VALUE_KEY = "value_key"*
*}*


*class AnyClass(valueMap: Map<String, Int>) {  fun getValue(): String {*
*    return valueMap[Constant.VALUE_KE]*

*  }}*

When I define the constant in the same file it works and starts showing the 
coverage. But this is a reusable constant which I want to use in many 
places.

and it shows:
Execution data for class */AnyClass does not match. 

I tried offline instrumentation as well but that did not work. 

below is my *build.gradle*


















































































*apply plugin: 'jacoco'configurations {    jacocoAnt    
jacocoRuntime}jacoco {    toolVersion = '0.8.8'}dependencies {    jacocoAnt 
group: 'org.jacoco', name: 'org.jacoco.ant', version: '0.8.8', classifier: 
'nodeps'    jacocoRuntime group: 'org.jacoco', name: 'org.jacoco.agent', 
version: '0.8.8', classifier: 'runtime'}//def testTaskName = 
"test${sourceName.capitalize()}UnitTest"project.afterEvaluate {    // Grab 
all build types and product flavors    def buildTypes = 
android.buildTypes.collect { type -> type.name <http://type.name/> }    def 
productFlavors = android.productFlavors.collect { flavor -> flavor.name 
<http://flavor.name/> }    // When no product flavors defined, use empty    
if (!productFlavors) productFlavors.add('')    productFlavors.each { 
productFlavorName ->        buildTypes.each { buildTypeName ->            
def sourceName, sourcePath            if (!productFlavorName) {            
    sourceName = sourcePath = "${buildTypeName}"            } else {        
        sourceName = "${productFlavorName}${buildTypeName.capitalize()}"    
            sourcePath = "${productFlavorName}/${buildTypeName}"            
}            def testTaskName = "test${sourceName.capitalize()}UnitTest"    
        def excludes = ['**/R.class',                            ......]    
        task "${testTaskName}Instrument"() {                ext.outputDir = 
buildDir.path + '/classes-instrumented'                doLast {            
        ant.taskdef(name: 'instrument',                            
classname: 'org.jacoco.ant.InstrumentTask',                            
classpath: configurations.jacocoAnt.asPath)                    
ant.instrument(destdir: outputDir) {                        fileset(dir: 
"${project.buildDir}/intermediates/javac", excludes: excludes)              
          fileset(dir: "${project.buildDir}/tmp/kotlin-classes", excludes: 
excludes)                    }                    
testProdUnitTest.classpath = files(outputDir) + 
testProdUnitTest.getClasspath()                }            }            
task "${testTaskName}Report"(dependsOn: ["${testTaskName}Instrument"]) {    
            doLast {                    ant.taskdef(name: 'report',        
                    classname: 'org.jacoco.ant.ReportTask',                
            classpath: configurations.jacocoAnt.asPath)                    
ant.report() {                        executiondata {                      
      ant.file(file: "$buildDir.path/jacoco/testProdUnitTest.exec")        
                }                        structure(name: 'Example') {      
                      classfiles {                                
fileset(dir: "${project.buildDir}/intermediates/javac", excludes: 
excludes)                                fileset(dir: 
"${project.buildDir}/tmp/kotlin-classes", excludes: excludes)              
              }                            sourcefiles {                    
            fileset(dir: 'src/main/java')                            }      
                  }                        html(destdir: 
"$buildDir.path/reports/jacoco")                    }                }      
      }        }    }*

*}*

Any solution/workaround I can try to resolve this?

Best Regards,
DharSam

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jacoco/db45e7ee-bf5b-48f4-8108-db6abdd9f776n%40googlegroups.com.

Reply via email to