Code Monkey home page Code Monkey logo

Comments (13)

mannodermaus avatar mannodermaus commented on June 4, 2024 1

I have invested some time into the integration of JaCoCo inside the JUnit 5 plugin myself now, since the topic seems to have been added to the backlog of the junit5 project. It's only available in the latest SNAPSHOT release as of now, so it's also not documented in the README, but here's the gist:

  • If you don't have it already, add the snapshot repository: maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
  • Update your plugin dependency to version 1.0.0.1-SNAPSHOT
  • Apply the jacoco plugin to your module
  • Optionally configure what reports should be generated by JaCoCo using the boolean junitPlatform.jacoco.***Report fields (where *** can be csv, xml or html)
  • Sync
  • Run code coverage tests using the per-variant jacocoTestReport*** tasks, or use the catch-all variant jacocoTestReport itself

I don't have much experience with JaCoCo myself, but I do get reports generated for the projects that I've tested this new snapshot in. Please let me know if there's anything wrong or missing with this approach! I'm also pinging @alixwar who was asking about this as well. Feedback is greatly appreciated! Especially regarding the new DSL config, do you guys think that's even necessary? We could also just leverage the global config declared by the jacoco plugin, instead of duplicating the on/off switches for the different report types...

from android-junit5.

alixwar avatar alixwar commented on June 4, 2024 1

Sorry for the late feedback but I've now tried 1.0.0.1-SNAPSHOT. I was forced to remove the workaround mentioned earlier (applyTo...) since otherwise there would be collisions of using the keyword jacoco.
So I removed the workarounds and run gradlew clean jacocoTestReportDebug

The good thing: I now get coverage for both "vanilla" JUnit4 tests and JUnit5 tests
Bad thing: Unit tests with runner "RobolectricTestRunner" still gives no code coverage. But I guess this is out-of-scope for this project.

Thank you very much @mannodermaus !

from android-junit5.

mannodermaus avatar mannodermaus commented on June 4, 2024 1

I have released the first official version of the plugin with JaCoCo integration as 1.0.10. You can now migrate away from the SNAPSHOT!

from android-junit5.

mannodermaus avatar mannodermaus commented on June 4, 2024 1

You can inspect the assembled Code Coverage tasks by adding --info to your Gradle invocation, then filter through the output to find the plugin's log statements (they are all prefixed with [android-junit5]). For each Jacoco task created by the plugin, the Execution Data, Source & Class Directories are logged. Maybe there's a discrepancy somewhere and the plugin doesn't figure out your project's structure correctly?

from android-junit5.

mannodermaus avatar mannodermaus commented on June 4, 2024

This is being discussed for the Java-based Gradle plugin over at junit-team/junit5 right now. If they decide to go for this enhancement, I'll definitely make sure to extend the Jacoco support for our variant-based needs!

from android-junit5.

alixwar avatar alixwar commented on June 4, 2024

Thanks for helping out with this @aurae
I've actually made it work for the official released versions in a multi-module setup (with the work-around) but not in combination with Robolectric at the moment (No coverage reported for tests run by RobolectricTestRunner, see: robolectric/robolectric#3397 )

Here is my working configuration (with Robolectric tests not working... Maybe you know why?): https://stackoverflow.com/a/46298696/1859486

from android-junit5.

alixwar avatar alixwar commented on June 4, 2024

An update: I verified the content of the exec file and it seems it's all in there, even the Robolectric tests.

Update 1: I suspect that I was looking at the wrong exec file. When I did the same tests now (more strictly looking at which exec files were enabled) I am not seeing coverage for JUnit5 tests.

Update 2: This work-around (based on: https://stackoverflow.com/a/39386661/1859486) makes sure that a .exec file is created per module:

project.afterEvaluate {
// Workaround: https://stackoverflow.com/questions/39362955/gradle-jacoco-and-junit5/39386661#39386661
    apply plugin: "jacoco"
    jacoco {
        applyTo junitPlatformTestDebug
    }
}

But the generated exec file only contains coverage data for vanilla JUnit4 tests.

from android-junit5.

benwicks avatar benwicks commented on June 4, 2024

@aurae which plugin are you referring to when you said the following?

Update your plugin dependency to version 1.0.0.1-SNAPSHOT

from android-junit5.

mannodermaus avatar mannodermaus commented on June 4, 2024

de.mannodermaus.gradle.plugins:android-junit5:1.0.0.1-SNAPSHOT

from android-junit5.

alixwar avatar alixwar commented on June 4, 2024

A question has been asked here if the Android plugin does something special. Maybe we can try to solve the last piece of the puzzle together to at least get a work-around until there is an official integration?

from android-junit5.

alixwar avatar alixwar commented on June 4, 2024

If anyone is interested I added a sample project with JUnit4, JUnit5, Mockito (JUnit4) and Robolectric (JUnit4) tests. I'm not getting any code coverage for the Robolectric test that I added in the sample: #18

Steps to reproduce:

  1. In the sample-robolectric folder, run: ..\gradlew clean jacocoTestReportDebug
  2. Examine the resulting $buildDir\jacoco\junitPlatformTestDebug.exec

Expected:
Code coverage for Foo.junit4robolectric(), Foo.junit4(), Foo.junit4mockito() and Foo.junit5()

Actual:
No code coverage for Foo.junit4robolectric()

from android-junit5.

sureshjoshi avatar sureshjoshi commented on June 4, 2024

Regarding this issue - I still can't seem to get any code coverage metrics (using the Jacoco plugin or vanilla Android Studio).

I get a report that tells me I have 0 coverage, with a suite that I know is close to 80% coverage.

Could there be anything missing other than:

classpath "de.mannodermaus.gradle.plugins:android-junit5:1.0.21"

...

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'de.mannodermaus.android-junit5'
apply plugin: 'jacoco'

...

testImplementation junit5()
testImplementation junit5Params() // Parameterized tests
testCompileOnly junit5EmbeddedRuntime() // AS3 workaround
testImplementation 'org.assertj:assertj-core:3.8.0'

The actual JUnit5 unit tests run great (using AssertJ)

from android-junit5.

sureshjoshi avatar sureshjoshi commented on June 4, 2024

Actually, this may be a problem with AS3.0 and Kotlin

https://issuetracker.google.com/issues/64929213

from android-junit5.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.