Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 3/Kotlin code coverage

My android app is multi module project:

include (android-app/kotlin-android)':application', (pure kotlin)':presentation', (pure kotlin)':domain', (android-library/kotin-android)':dataproviders'

I'm using Junit/Mockito for tests and I have issue with generating code coverage for kotlin android modules only. code coverage report Tested lines are visible for android studio.

tested class in ui.viewmodel package:

tested lines for kotlin-android module

But, for pure kotlin (eg. domain, presentation) test coverage works fine: code coverage report pure kotlin module

I'm using Android Studio 3.0 Canary 8 You can look at my build.gradle files at github:

build.gradle

dependencies.gradle

application.build.gradle

presentation.build.gradle

Example test in android application module:

MostPopularViewModelTest

Example test in pure kotlin module:

MostPopularPresenterTest

Can someone help me with my problem? I tried generate code coverage via Jacoco but it also did not show code coverage.

like image 246
Hype Avatar asked Jul 27 '17 12:07

Hype


1 Answers

Solution is to add this this gradle task in build.gradle for module:

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

And run:

gradlew copyTestClasses

Then generate code coverage report without problems.

like image 65
Hype Avatar answered Sep 27 '22 17:09

Hype