@@ -9,7 +9,7 @@ A Gradle plugin that allows for the execution of [JUnit 5][junit5gh] unit tests
99``` groovy
1010buildscript {
1111 dependencies {
12- classpath "de.mannodermaus.gradle.plugins:android-junit5:1.0.0 "
12+ classpath "de.mannodermaus.gradle.plugins:android-junit5:1.0.10 "
1313 }
1414}
1515```
@@ -27,51 +27,104 @@ dependencies {
2727
2828 // (Optional) If you need "parameterized tests"
2929 testImplementation junit5Params()
30-
31- // For Android Studio users:
32- //
33- // All versions up to and including AS 3.0 Beta 5 use a build of IntelliJ IDEA
34- // that depends on APIs of an outdated Milestone Release of JUnit 5.
35- // Therefore, your tests will fail with a NoSuchMethodError
36- // when executed from Android Studio directly.
37- //
38- // To prevent this, there is a separate library you can apply here.
39- // It provides a copy of the JUnit 5 Runtime used in a more recent build
40- // of IntelliJ, overriding the one embedded in Android Studio.
41- //
42- // Please note the version of this dependency! There was an issue with the deployment
43- // of the "1.0.0" JAR, so that one actually won't work as advertised. Please explicitly
44- // depend on this version instead; there won't be any incompatibilities with the main plugin,
45- // since this doesn't share any connection with it. Sorry for the inconvenience!
46- testCompileOnly "de.mannodermaus.gradle.plugins:android-junit5-embedded-runtime:1.0.0-RC3-rev1"
4730}
4831```
4932
5033## Usage
5134
52- This plugin configures the ` junitPlatform ` task for each registered build variant of a project.
53- It automatically attaches both the Jupiter & Vintage Engines during the execution phase of your tests.
35+ This plugin configures a ` junitPlatformTest ` task for each registered build variant of a project.
36+ It automatically attaches both the Jupiter & Vintage Engines during the execution phase of your tests as well .
5437
5538More instructions on how to write JUnit 5 tests can be found [ in their User Guide] [ junit5ug ] .
5639Furthermore, this repository provides a small showcase of the functionality provided by JUnit 5 [ here] [ sampletests ] .
5740
41+ ## Android Studio Workarounds
42+
43+ > ** Note:**
44+ >
45+ > The following section deals with fixing Test Execution within ** Android Studio 3** .
46+ > Running your JUnit 5 tests directly from Android Studio 2.3.3 and earlier ** will not work** :
47+ > You will encounter an ` AbstractMethodError ` when trying to do so ([ more information here] [ as2issue ] ).
48+ >
49+ > The cause of this error is similar in nature to the one described below, and related to outdated APIs.
50+ > Unlike that issue though, we can't fix the ` AbstractMethodError ` inside IntelliJ's internal runtime
51+ > in the same way. Therefore, please resort to using Gradle for unit testing in Android Studio 2.
52+
53+
54+ All versions up to and including ** Android Studio 3.0 Beta 7** are built
55+ on a version of IntelliJ IDEA that depends on outdated JUnit 5 APIs.
56+ Therefore, your tests will fail with an Exception similar to the following when you try to
57+ launch your tests from inside the IDE (using an * Android JUnit* Run Configuration):
58+
59+ ```
60+ Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.launcher.Launcher.execute(Lorg/junit/platform/launcher/LauncherDiscoveryRequest;)V
61+ at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:42)
62+ ...
63+ ```
64+
65+ To work around this, there is a separate dependency you can add to the * test* scope
66+ of your project in Android Studio 3. It provides its own copy of the JUnit 5 Runtime
67+ provided by a more recent build of IntelliJ, overriding the one embedded in Android Studio.
68+
69+ To use this, add the following line alongside the other ` junit5() ` dependencies:
70+
71+ ``` groovy
72+ testCompileOnly junit5EmbeddedRuntime()
73+ ```
74+
75+ * As mentioned above, this will ** only** fix Test Execution from Android Studio 3.*
76+
5877## Extras
5978
79+ ### Override Dependency Versions
80+
6081Inside the configuration closure applied by the plugin, you can specify the same properties as you would
6182for a Java-based project with the JUnit Platform Gradle plugin.
6283However, there are some additional properties that you can apply:
6384
6485``` groovy
6586junitPlatform {
6687 // The JUnit Jupiter dependency version to use; matches the platform's version by default
67- jupiterVersion "5.0.0 "
88+ jupiterVersion "5.0.1 "
6889 // The JUnit Vintage Engine dependency version to use; matches the platform's version by default
69- vintageVersion "4.12.0 "
90+ vintageVersion "4.12.1 "
7091}
7192```
7293
94+ ### JaCoCo Integration
95+
96+ If the plugin detects the usage of [ JaCoCo] [ jacoco ] inside a project that it's being applied to,
97+ it will automatically configure additional tasks to report the unit test coverage
98+ of your application based on its JUnit 5 tests.
99+ There is no additional setup required to enable this behaviour.
100+ You can however customize the reports JaCoCo should generate.
101+
102+ Configuration is applied through the ` jacoco ` clause inside the plugin's DSL:
103+
104+ ``` groovy
105+ junitPlatform {
106+ jacoco {
107+ csvReport true
108+ xmlReport true
109+ htmlReport true
110+ }
111+ }
112+ ```
113+
114+ ## License
115+
116+ ` android-junit5 ` is distributed with multiple Open Source licenses:
117+
118+ - ` android-junit5-embedded-runtime ` uses [ Apache License v2.0] ( android-junit5-embedded-runtime/LICENSE.md )
119+ - All other modules use [ Eclipse Public License v2.0] ( android-junit5/LICENSE.md )
120+
121+ Please see the ` LICENSE.md ` files in the subfolders for more details.
122+
73123 [ junit5gh ] : https://github.com/junit-team/junit5
74124 [ junit5ug ] : http://junit.org/junit5/docs/current/user-guide
75125 [ travisci ] : https://travis-ci.org/mannodermaus/android-junit5
76- [ sonatyperepo ] : https://oss.sonatype.org/content/repositories/snapshots
126+ [ as2issue ] : https://github.com/mannodermaus/android-junit5/issues/19
127+ [ jacoco ] : http://www.eclemma.org/jacoco
128+ [ sonatyperepo ] : https://oss.sonatype.org/content/repositories/snapshots/de/mannodermaus/gradle/plugins
77129 [ sampletests ] : sample/src/test
130+ [ licensefile ] : LICENSE.md
0 commit comments