Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 515 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Android studio code coverage not showing any Kotlin classes

#1
I have 2 Kotlin based AS projects. One works fine, the other doesn't. Both have an identical structure and gradle config. I'm using Kotlin 1.1.4-2 with AS 3.0b2.

The problem is that when I run code coverage, the classes I'm testing do not even show up under the coverage report. The only thing I see is R.java and BuildConfig.java, but none of my source files are being found.

All source files are Kotlin based. I'm using Spek for my unit testing. Same setup and versions as my other functional project. I tried using both JaCoCo and Jetbrains code coverage and neither works.

I apologize, I'm not able to embed pictures yet.

This is the problem:

![coverage report][1]

Here's my project structure:

![file structure][2]

And here's my gradle android block:

compileSdkVersion 26
buildToolsVersion "26.0.1"

defaultConfig {
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName libraryVersion
}

buildTypes {
debug {
testCoverageEnabled = true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

and my dependencies:

implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation "io.reactivex.rxjava2:rxkotlin:2.1.0"

testImplementation 'junit:junit:4.12'
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
testImplementation 'org.jetbrains.spek:spek-api:1.1.2'
testImplementation 'org.jetbrains.spek:spek-junit-platform-engine:1.1.2'
testImplementation 'org.junit.platform:junit-platform-runner:1.0.0-M4'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.0.0-M4'

implementation 'com.android.support:appcompat-v7:26.0.1'

implementation 'com.squareup.okhttp3:okhttp-ws:3.3.1'
implementation 'com.google.protobuf:protobuf-java:2.6.1'

I've tried running

task copyTestClasses(type: Copy) {
from "build/tmp/kotlin-classes/debugUnitTest"
into "build/intermediates/classes/debug"
}

task copySdkClasses(type: Copy) {
from "build/tmp/kotlin-classes/debug"
into "build/intermediates/classes/debug"
}

before my testing and that doesn't work either.

What's strange is my other project, using the same AS version, Kotlin version, and project structure, is working fine and generating proper code coverage.

Any help would be appreciated.

[1]:

[2]:
Reply

#2
Try to use JaCoco for coverage, this is a IntelliJ IDEA issue: [Kotlin inline keyword causing IntelliJ IDEA Coverage reporting 0%
][1]

How to use JaCoco to get the coverage:
[Making Android Studio Test Coverage works][2]

Resume:

1. Click on edit configurations

![Edit configurations][3]

2. Go to Run/Debug Configurations -> Defaults -> Android JUnit -> Code Coverage

![Code coverage configuration][4]

3. Choose coverage Runner: Select JaCoCo

4. Apply -> OK

5. Run your test again and voila you will get the coverage

[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[4]:
Reply

#3
Kotlin announced the new [kotlinx-kover] Gradle plugin compatible with JaCoCo and IntelliJ.
It resolves the problem with `inline` functions and maybe more.

```kotlin
plugins {
id("org.jetbrains.kotlinx.kover") version "0.5.0"
}
```

> Once applied, the plugin can be used out of the box without additional configuration.


Watch its [YouTube announcement video] and also track its roadmap from [this youtrack issue].

[kotlinx-kover]:

[To see links please register here]

[YouTube announcement video]:
[this youtrack issue]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through