Skip to content

Commit 8964b59

Browse files
committed
Extend README with more info on dependency handlers, JaCoCo & workarounds
1 parent a0bc02b commit 8964b59

File tree

2 files changed

+79
-23
lines changed

2 files changed

+79
-23
lines changed

README.md

Lines changed: 75 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A Gradle plugin that allows for the execution of [JUnit 5][junit5gh] unit tests
99
```groovy
1010
buildscript {
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

5538
More instructions on how to write JUnit 5 tests can be found [in their User Guide][junit5ug].
5639
Furthermore, 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()` dependency:
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+
6081
Inside the configuration closure applied by the plugin, you can specify the same properties as you would
6182
for a Java-based project with the JUnit Platform Gradle plugin.
6283
However, there are some additional properties that you can apply:
6384

6485
```groovy
6586
junitPlatform {
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
126+
[as2issue]: https://github.com/mannodermaus/android-junit5/issues/19
127+
[jacoco]: http://www.eclemma.org/jacoco
76128
[sonatyperepo]: https://oss.sonatype.org/content/repositories/snapshots
77129
[sampletests]: sample/src/test
130+
[licensefile]: LICENSE.md

android-junit5-embedded-runtime/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ targetCompatibility = JavaVersion.VERSION_1_6
2020
// Dependency Definitions
2121
// This module exports a "fat JAR" containing embedded JARs from IntelliJ IDEA,
2222
// using a shadowed JAR that overrides the default build artifact.
23+
//
24+
// Path to this JAR inside an IntelliJ IDEA package:
25+
// "plugins/junit/lib/junit5-rt.jar"
2326
// ------------------------------------------------------------------------------------------------
2427

2528
dependencies {
@@ -31,7 +34,7 @@ shadowJar {
3134
classifier = null
3235
}
3336

34-
build.doLast { shadowJar.execute() }
37+
build.finalizedBy shadowJar
3538

3639
// ------------------------------------------------------------------------------------------------
3740
// Deployment Setup

0 commit comments

Comments
 (0)