Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android "viewModelScope.launch" block not fully covered for Kotlin 1.6.10 #1290

Closed
AnneJ17 opened this issue Feb 23, 2022 · 11 comments
Closed

Comments

@AnneJ17
Copy link

AnneJ17 commented Feb 23, 2022

Steps to reproduce

  • JaCoCo version: 0.8.7
  • Operating system: MacOS
  • Steps: When using Jacoco tool for reporting code coverage in my Android project with Kotlin version of 1.6.10, the Jacoco reports for viewModelScope.launch { ... } block is always NOT fully covered.

Expected behaviour

viewModelScope.launch { ... } should be marked as fully covered by jacoco for Kotlin 1.6.10.

Actual behaviour

The report says 2 of 3 branches missed for viewModelScope.launch { ... } block.
image

@AnneJ17 AnneJ17 added the type: bug 🐛 Something isn't working label Feb 23, 2022
@Godin
Copy link
Member

Godin commented Feb 24, 2022

@AnneJ17

with Kotlin version of 1.6.10

Do you get the same result with other versions? e.g. with 1.4.10 or 1.5.32?

JaCoCo version: 0.8.7

Are you sure? How we can verify this?

Because of closed long time ago #1126 and #1123 we have to ask all those questions in the absence of complete reproducer from you.

And in any case JaCoCo performs analysis of bytecode, so we can't investigate your case without looking at your class files - please provide at least them.

@Godin Godin added the reproducer required Further information is requested label Feb 24, 2022
@AnneJ17
Copy link
Author

AnneJ17 commented Feb 24, 2022

@Godin I get the same result with 1.4.10 and 1.5.32 using JaCoCo version 0.8.7. I have attached both class file and the bytecode of the class below. Please let me know if there is any additional information that you may require.

GoalDetailsViewModel.class.zip
bytecode.txt

@Godin
Copy link
Member

Godin commented Feb 24, 2022

@AnneJ17

I get the same result with 1.4.10 and 1.5.32 using JaCoCo version 0.8.7

Same as before - please understand that we can't verify this statement without complete reproducer / access to your project.

I have attached both class file and the bytecode of the class below

{ ... } in your viewModelScope.launch { ... } is lambda, so it's bytecode is not stored in GoalDetailsViewModel.class file but in another one next to it, so please provide all class-files.

@AnneJ17
Copy link
Author

AnneJ17 commented Feb 24, 2022

@Godin
bytecode.txt
GoalDetailsFragment.class.zip
Sorry about that. In this class is where that function that launches the coroutine is invoked. This is a huge project, so I will try my best to give you the files that will help you to find the issue. Thank you in advance. Please let me know if this won't work, I can create a sample project mimicking this scenario.

@Godin
Copy link
Member

Godin commented Mar 1, 2022

bytecode.txt
GoalDetailsFragment.class.zip
Sorry about that. In this class is where that function that launches the coroutine is invoked.

No this is not what is needed for investigations and not what was requested.

This is a huge project, so I will try my best to give you the files that will help you to find the issue. Thank you in advance. Please let me know if this won't work, I can create a sample project mimicking this scenario.

Either simply provide all class files as was requested,
or if simpler for you - indeed create a small one from scratch to demonstrate the same problem.

@AnneJ17
Copy link
Author

AnneJ17 commented Mar 2, 2022

Either simply provide all class files as was requested, or if simpler for you - indeed create a small one from scratch to demonstrate the same problem.

Hi @Godin, here is the link to the repo that reproduces this scenario.
Thanks once again for your time and patience.

@Godin
Copy link
Member

Godin commented Mar 3, 2022

here is the link to the repo that reproduces this scenario.

Even not taking into account that you don't provide description of steps to compile this project, it doesn't look like anyone other than you can easily build this project without modifications - here is what I tried

git clone https://github.com/AnneJ17/jacoco-miss-launch
cd jacoco-miss-launch

docker run --rm -v `pwd`:/project mingc/android-build-box bash -c 'cd /project; ./gradlew :coroutinelaunch:assembleDebug'

and it failed as following

* What went wrong:
Execution failed for task ':coroutinelaunch:dataBindingMergeDependencyArtifactsDebug'.
> Could not resolve all files for configuration ':coroutinelaunch:debugCompileClasspath'.
   > Could not resolve androidx.databinding:viewbinding:7.0.4.
     Required by:
         project :coroutinelaunch
      > Could not resolve androidx.databinding:viewbinding:7.0.4.
         > Could not parse POM https://jfrog.info53.com/artifactory/fitb-development-virtual/androidx/databinding/viewbinding/7.0.4/viewbinding-7.0.4.pom

So please either make it buildable by others,
or provide all compiled class files - build this project by yourself and simply commit all produced files and reports into the repository.

@AnneJ17
Copy link
Author

AnneJ17 commented Mar 3, 2022

Even not taking into account that you don't provide description of steps to compile this project, it doesn't look like anyone other than you can easily build this project without modifications - here is what I tried

My sincere apologies. I have updated the project and have included the steps to get the Jacoco report in the README file.

@Godin
Copy link
Member

Godin commented Mar 4, 2022

included the steps

After following your steps

git clone https://github.com/AnneJ17/jacoco-miss-launch
cd jacoco-miss-launch
./gradlew ":coroutinelaunch:jacocoDebugTestReport"
open coroutinelaunch/build/reports/jacoco/jacocoDebugTestReport/html/index.html

you can see following report

Screenshot 2022-03-04 at 01 19 56

please pay attention on the JaCoCo version at the right bottom corner of the report,
so as was suspected from the beginning in #1290 (comment)
to generate report you actually use JaCoCo version 0.8.6 and not 0.8.7 as you claimed.

After following modification of your coroutinelaunch/jacoco.gradle

 apply plugin: 'jacoco'
+jacoco.toolVersion = "0.8.7"

and execution

./gradlew ":coroutinelaunch:jacocoDebugTestReport"
open coroutinelaunch/build/reports/jacoco/jacocoDebugTestReport/html/index.html

report is

Screenshot 2022-03-04 at 01 25 41

And so btw I highly suspect that statement about Kotlin version

I get the same result with 1.4.10

was not true also.

@Godin Godin closed this as completed Mar 4, 2022
@Godin Godin added declined: invalid ❌ and removed type: bug 🐛 Something isn't working reproducer required Further information is requested labels Mar 4, 2022
@JEMoralesD
Copy link

JEMoralesD commented Mar 30, 2022

I am having the same issue on jacoco 0.8.7 with kotlin 1.6.10.

In my report there are two similar methods with a unit test that does practically the same, the only difference is that one updates a MutableSharedFlow while the one that is reported as partially covered is a MutableStateFlow

jacoco

Btw in my case the dispatchers only provide the default android kotlin dispatchers

{
    override val main: CoroutineDispatcher
        get() = Dispatchers.Main
    override val io: CoroutineDispatcher
        get() = Dispatchers.IO
    override val default: CoroutineDispatcher
        get() = Dispatchers.Default
}

And I am using the Turbine package to create the unit tests for this corroutine scopes

@Godin
Copy link
Member

Godin commented Mar 30, 2022

@JEMoralesD

I am having the same issue

You can't have exactly the same issue, because from your screenshot seems that you use JaCoCo 0.8.7 whereas issue discussed here was due to use of JaCoCo 0.8.6 instead of 0.8.7.

So if you believe that something is still not working properly with 0.8.7, then please first create complete executable reproducer that others can try, and then share it with us by creating new ticket.

@jacoco jacoco locked as resolved and limited conversation to collaborators Mar 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants