Comments (13)
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 becsv
,xml
orhtml
) - Sync
- Run code coverage tests using the per-variant
jacocoTestReport***
tasks, or use the catch-all variantjacocoTestReport
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.
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.
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.
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.
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.
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.
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.
@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.
de.mannodermaus.gradle.plugins:android-junit5:1.0.0.1-SNAPSHOT
from android-junit5.
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.
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:
- In the sample-robolectric folder, run:
..\gradlew clean jacocoTestReportDebug
- 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.
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.
Actually, this may be a problem with AS3.0 and Kotlin
https://issuetracker.google.com/issues/64929213
from android-junit5.
Related Issues (20)
- Add support for Gradle Plugins DSL HOT 2
- org.junit.runners.model.InvalidTestClassError starting with Android Studio Dolphin | 2021.3.1 HOT 8
- Build broken when using kotlin 1.7.21 HOT 1
- Clarification with regards to JaCoCo HOT 2
- AGP 8.0.0-alpha10 HOT 6
- Various 'Unable to resolve' log messages for Android tests HOT 4
- Parallel concurrent execution of instrumentation tests HOT 6
- NoClassDefFoundError: org/jetbrains/kotlin/gradle/plugin/KotlinPluginKt with Kotlin 1.8.20 HOT 5
- `@Tag` at the class level results in test number mismatch HOT 6
- NoSuchMethodError: 'org.gradle.api.provider.Property org.gradle.api.reporting.ConfigurableReport.getOutputLocation()' on Gradle 7.5.1 HOT 3
- Is it possible to run junit5 tests with robolectric? HOT 5
- Encountering problems when trying to integrate the plugin HOT 1
- Log not working with ParameterizedTest HOT 1
- Support per-test log display for JUnit 5 instrumentation tests HOT 4
- Readme should include apply plugin for legacy syntax HOT 1
- "Expected N+1 tests, received N" caused by fun with @TestTemplate HOT 4
- Invalid test names for repeated and parametrized tests HOT 8
- Usage of ComposeExtension flags a false-positive warning in newer IDEs HOT 1
- sumas HOT 1
- AGP 8.4.1 gives issue due to usage of deprecated API HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-junit5.