-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Document code or automatically configure Jacoco with Junit 5 Gradle Plugin #1024
Comments
IIRC Currently, the Jacoco plugin hooks into the test task. Could it be extended to support junitPlatformTest (at least until Gradle provides core support for the new JUnit platform)? |
@JLLeitschuh Do you know of a workaround for Gradle (Android) Java? My attempt unfortunately only results in code coverage data for JUnit4 tests |
Does the android plugin do something special for testing? I'm not totally certain because I've never done anything with it. I guess my first question is can you get the junit 5 plugin to correctly execute your tests? Once you have that working the above should work. |
@JLLeitschuh I have done the following for each submodule in the project:
This is enough to generate code coverage for JUnit4 tests (inluding tests annotated
Do you mean the Android Gradle plugin or the Android JUnit 5 plugin? |
As opposed to the Java-based Gradle plugin for JUnit 5 provided by the junit5 team? It basically only extends its core functionality with the variant-awareness that Android projects have. Instead of adding just a single |
@JLLeitschuh Any thoughts on the explanation from @mannodermaus ? Is there something that I or someone else can do to help clarify the issue? |
I don't work with any projects that use gradle for building android projects. I'm assuming that as long as you can get your android tests to run correctly using the If you have specific behaviour problems that you are experiencing then I may be able to help. At the moment I'm not totally certain I understand what the problem is. |
As discussed over at mannodermaus/android-junit5#4, the latest SNAPSHOT release of the Android-based plugin for JUnit 5 implements the first iteration of support for Jacoco out of the box, so there's nothing to be done from you guys in that regard. As for the Java-based JUnit 5 Gradle plugin, it could be a nice improvement to apply the code snippet for Jacoco integration directly through the plugin in a future release. In the android-junit5 plugin, I'm conditionally extending each JUnit 5 task with a corresponding Jacoco reporting task only if the plugin is found to exist in a module. |
I'm happy to report that from my perspective the issue with JUnit5 is resolved on Android. It works fine with the latest snapshot release of the plugin. |
@JLLeitschuh I've created a sample project with the following tests (for a related issue):
Sample project: mannodermaus/android-junit5#18 Steps to reproduce:
Expected: Actual: I realize that this is more of a problem for the Robolectric project (I've reported it here: robolectric/robolectric#3397) but if any of you guys, who know much more about this than I, could take a quick peek and pin point what seems to be wrong it would be easier for someone else to find a workaround or to make a pull request and fix the issue in the Robolectric project so that Android developers (Robolectric is quite common) can start with JUnit5. |
@JLLeitschuh 's solution worked but the idea groovy linter wasn't too happy. This was my final solution. For Gradle 4.4.1
|
clean up all old JUnit dependencies (the mp3spi reference junit 3.8.). Implement jacoco support for the JUnit 5 test results (see: junit-team/junit5#1024) Closes #79
@domhauton Is there a better solution now that Gradle 4.6 is out with a new way of handling JUnit 5? |
@Thunderforge I guess, with Gradle 4.6 and |
Since Gradle now provides native support for running tests on the JUnit Platform, JaCoCo should work without any extra configuration. We've decided to deprecate our custom plugin (see #1317 for details) and not add any new features to it. Thus, I'm closing this issue. |
Feature (or Documentation) Request
Should the Junit 5 plugin automatically configure the
junitPlatformTest
task to use Jacoco if it detects the plugin?Currently configuring jacoco with Junit 5 requires a bit of digging into the DSL and figuring out its intricacies.
Perhaps configure the Junit5 plugin should be expanded to have a
enableJacoco
flag that will add ajacocoJunit5TestReport
task if set totrue
? What are the teams thoughts?Current solutions
Anyone looking to configure jacoco with Junit 5 using the new Gradle Kotlin DSL you currently need to use a bit of a workaround because of a kotlin compiler bug. This code is known to work with Gradle 4.1
EDIT
Better solution with less code:
Deliverables
The text was updated successfully, but these errors were encountered: