Skip to content

Commit 45a2d72

Browse files
authored
Update to JUnit 5.5.2 & auto-generate README (#186)
* Gradle 5.6.2 * Bump versions of all dependencies * Add a template file for README.md, auto-injecting dependency versions * Autofind root folder * Bump plugin version * Add generate-readme task * Update readme * Update logo psd
1 parent 15da2ef commit 45a2d72

File tree

9 files changed

+361
-25
lines changed

9 files changed

+361
-25
lines changed

.images/logo.psd

692 Bytes
Binary file not shown.

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Furthermore, this repository provides a small showcase of the functionality prov
1919
```groovy
2020
buildscript {
2121
dependencies {
22-
classpath "de.mannodermaus.gradle.plugins:android-junit5:1.5.1.0"
22+
classpath "de.mannodermaus.gradle.plugins:android-junit5:1.5.2.0"
2323
}
2424
}
2525
```
@@ -31,7 +31,7 @@ Furthermore, this repository provides a small showcase of the functionality prov
3131
```kotlin
3232
buildscript {
3333
dependencies {
34-
classpath("de.mannodermaus.gradle.plugins:android-junit5:1.5.1.0")
34+
classpath("de.mannodermaus.gradle.plugins:android-junit5:1.5.2.0")
3535
}
3636
}
3737
```
@@ -51,15 +51,15 @@ Snapshots of the development version are available through [Sonatype's `snapshot
5151
5252
dependencies {
5353
// (Required) Writing and executing Unit Tests on the JUnit Platform
54-
testImplementation "org.junit.jupiter:junit-jupiter-api:5.5.1"
55-
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.5.1"
54+
testImplementation "org.junit.jupiter:junit-jupiter-api:5.5.2"
55+
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.5.2"
5656
5757
// (Optional) If you need "Parameterized Tests"
58-
testImplementation "org.junit.jupiter:junit-jupiter-params:5.5.1"
58+
testImplementation "org.junit.jupiter:junit-jupiter-params:5.5.2"
5959
6060
// (Optional) If you also have JUnit 4-based tests
6161
testImplementation "junit:junit:4.12"
62-
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:5.5.1"
62+
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:5.5.2"
6363
}
6464
```
6565
</details>
@@ -74,15 +74,15 @@ Snapshots of the development version are available through [Sonatype's `snapshot
7474

7575
dependencies {
7676
// (Required) Writing and executing Unit Tests on the JUnit Platform
77-
testImplementation("org.junit.jupiter:junit-jupiter-api:5.5.1")
78-
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.5.1")
77+
testImplementation("org.junit.jupiter:junit-jupiter-api:5.5.2")
78+
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.5.2")
7979

8080
// (Optional) If you need "Parameterized Tests"
81-
testImplementation("org.junit.jupiter:junit-jupiter-params:5.5.1")
81+
testImplementation("org.junit.jupiter:junit-jupiter-params:5.5.2")
8282

8383
// (Optional) If you also have JUnit 4-based tests
8484
testImplementation("junit:junit:4.12")
85-
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.5.1")
85+
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.5.2")
8686
}
8787
```
8888
</details>
@@ -129,8 +129,8 @@ To start writing instrumentation tests with JUnit Jupiter, make the following ch
129129
130130
dependencies {
131131
// 5) Jupiter API & Test Runner, if you don't have it already
132-
androidTestImplementation "androidx.test:runner:1.1.1"
133-
androidTestImplementation "org.junit.jupiter:junit-jupiter-api:5.5.1"
132+
androidTestImplementation "androidx.test:runner:1.2.0"
133+
androidTestImplementation "org.junit.jupiter:junit-jupiter-api:5.5.2"
134134
135135
// 6) The instrumentation test companion libraries
136136
androidTestImplementation "de.mannodermaus.junit5:android-test-core:1.1.0"
@@ -164,8 +164,8 @@ To start writing instrumentation tests with JUnit Jupiter, make the following ch
164164
}
165165
dependencies {
166166
// 5) Jupiter API & Test Runner, if you don't have it already
167-
androidTestImplementation("androidx.test:runner:1.1.1")
168-
androidTestImplementation("org.junit.jupiter:junit-jupiter-api:5.5.1")
167+
androidTestImplementation("androidx.test:runner:1.2.0")
168+
androidTestImplementation("org.junit.jupiter:junit-jupiter-api:5.5.2")
169169
170170
// 6) The instrumentation test companion libraries
171171
androidTestImplementation("de.mannodermaus.junit5:android-test-core:1.1.0")

README.md.template

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
# android-junit5 [![CircleCI](https://circleci.com/gh/mannodermaus/android-junit5/tree/master.svg?style=svg)][circleci]
2+
3+
![Logo](.images/logo.png)
4+
5+
A Gradle plugin that allows for the execution of [JUnit 5][junit5gh] tests in Android environments using **Android Gradle Plugin 3.2.0 or later.**
6+
7+
## How?
8+
9+
This plugin configures the unit test tasks for each build variant of a project to run on the JUnit Platform. Furthermore, it provides additional configuration options for these tests [through a DSL][wiki-dsl] attached to `android.testOptions`.
10+
11+
Instructions on how to write JUnit 5 tests can be found [in their User Guide][junit5ug].
12+
Furthermore, this repository provides a small showcase of the functionality provided by JUnit 5 [here][sampletests].
13+
14+
## Download
15+
16+
<details open>
17+
<summary>Groovy</summary>
18+
19+
```groovy
20+
buildscript {
21+
dependencies {
22+
classpath "de.mannodermaus.gradle.plugins:android-junit5:${pluginVersion}"
23+
}
24+
}
25+
```
26+
</details>
27+
28+
<details>
29+
<summary>Kotlin</summary>
30+
31+
```kotlin
32+
buildscript {
33+
dependencies {
34+
classpath("de.mannodermaus.gradle.plugins:android-junit5:${pluginVersion}")
35+
}
36+
}
37+
```
38+
</details>
39+
40+
<br/>
41+
42+
Snapshots of the development version are available through [Sonatype's `snapshots` repository][sonatyperepo].
43+
44+
## Setup
45+
46+
<details open>
47+
<summary>Groovy</summary>
48+
49+
```groovy
50+
apply plugin: "de.mannodermaus.android-junit5"
51+
52+
dependencies {
53+
// (Required) Writing and executing Unit Tests on the JUnit Platform
54+
testImplementation "org.junit.jupiter:junit-jupiter-api:${Versions.org_junit_jupiter}"
55+
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${Versions.org_junit_jupiter}"
56+
57+
// (Optional) If you need "Parameterized Tests"
58+
testImplementation "org.junit.jupiter:junit-jupiter-params:${Versions.org_junit_jupiter}"
59+
60+
// (Optional) If you also have JUnit 4-based tests
61+
testImplementation "junit:junit:${Versions.junit}"
62+
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:${Versions.junit_vintage_engine}"
63+
}
64+
```
65+
</details>
66+
67+
<details>
68+
<summary>Kotlin</summary>
69+
70+
```kotlin
71+
plugins {
72+
id("de.mannodermaus.android-junit5")
73+
}
74+
75+
dependencies {
76+
// (Required) Writing and executing Unit Tests on the JUnit Platform
77+
testImplementation("org.junit.jupiter:junit-jupiter-api:${Versions.org_junit_jupiter}")
78+
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${Versions.org_junit_jupiter}")
79+
80+
// (Optional) If you need "Parameterized Tests"
81+
testImplementation("org.junit.jupiter:junit-jupiter-params:${Versions.org_junit_jupiter}")
82+
83+
// (Optional) If you also have JUnit 4-based tests
84+
testImplementation("junit:junit:${Versions.junit}")
85+
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:${Versions.junit_vintage_engine}")
86+
}
87+
```
88+
</details>
89+
90+
<br/>
91+
92+
More information on Getting Started can be found [on the wiki][wiki-gettingstarted].
93+
94+
## Requirements
95+
96+
The latest version of this plugin requires:
97+
* Android Gradle Plugin `3.2.0` or above
98+
* Gradle `4.7` or above
99+
100+
## Instrumentation Test Support
101+
102+
There is experimental support for Android instrumentation tests, which requires some additional configuration & dependencies. Furthermore, because JUnit 5 is built on Java 8 from the ground up, its instrumentation tests will only run on devices running Android 8.0 (API 26) or newer. Older phones will skip the execution of these tests completely, marking them as "ignored".
103+
104+
To start writing instrumentation tests with JUnit Jupiter, make the following changes to your module's build script:
105+
106+
<details open>
107+
<summary>Groovy</summary>
108+
109+
```groovy
110+
android {
111+
defaultConfig {
112+
// 1) Make sure to use the AndroidJUnitRunner, of a subclass of it. This requires a dependency on androidx.test:runner, too!
113+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
114+
// 2) Connect JUnit 5 to the runner
115+
testInstrumentationRunnerArgument "runnerBuilder", "de.mannodermaus.junit5.AndroidJUnit5Builder"
116+
}
117+
118+
// 3) Java 8 is required
119+
compileOptions {
120+
sourceCompatibility JavaVersion.VERSION_1_8
121+
targetCompatibility JavaVersion.VERSION_1_8
122+
}
123+
124+
// 4) JUnit 5 will bundle in files with identical paths; exclude them
125+
packagingOptions {
126+
exclude "META-INF/LICENSE*"
127+
}
128+
}
129+
130+
dependencies {
131+
// 5) Jupiter API & Test Runner, if you don't have it already
132+
androidTestImplementation "androidx.test:runner:${Versions.androidx_test_runner}"
133+
androidTestImplementation "org.junit.jupiter:junit-jupiter-api:${Versions.org_junit_jupiter}"
134+
135+
// 6) The instrumentation test companion libraries
136+
androidTestImplementation "de.mannodermaus.junit5:android-test-core:${instrumentationVersion}"
137+
androidTestRuntimeOnly "de.mannodermaus.junit5:android-test-runner:${instrumentationVersion}"
138+
}
139+
```
140+
</details>
141+
142+
<details>
143+
<summary>Kotlin</summary>
144+
145+
```groovy
146+
android {
147+
defaultConfig {
148+
// 1) Make sure to use the AndroidJUnitRunner, of a subclass of it. This requires a dependency on androidx.test:runner, too!
149+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
150+
// 2) Connect JUnit 5 to the runner
151+
testInstrumentationRunnerArgument("runnerBuilder", "de.mannodermaus.junit5.AndroidJUnit5Builder")
152+
}
153+
154+
// 3) Java 8 is required
155+
compileOptions {
156+
setSourceCompatibility(JavaVersion.VERSION_1_8)
157+
setTargetCompatibility(JavaVersion.VERSION_1_8)
158+
}
159+
160+
// 4) JUnit 5 will bundle in files with identical paths; exclude them
161+
packagingOptions {
162+
exclude("META-INF/LICENSE*")
163+
}
164+
}
165+
dependencies {
166+
// 5) Jupiter API & Test Runner, if you don't have it already
167+
androidTestImplementation("androidx.test:runner:${Versions.androidx_test_runner}")
168+
androidTestImplementation("org.junit.jupiter:junit-jupiter-api:${Versions.org_junit_jupiter}")
169+
170+
// 6) The instrumentation test companion libraries
171+
androidTestImplementation("de.mannodermaus.junit5:android-test-core:${instrumentationVersion}")
172+
androidTestRuntimeOnly("de.mannodermaus.junit5:android-test-runner:${instrumentationVersion}")
173+
}
174+
```
175+
</details>
176+
177+
The `android-test-core` artifact includes an extension point for the `ActivityScenario` API; more information on that can be found in the wiki.
178+
179+
# Official Support
180+
181+
At this time, Google hasn't shared any immediate plans to bring first-party support for JUnit 5 to Android. The following list is an aggregation of pending feature requests:
182+
183+
- [InstantTaskExecutorRule uses @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) -- why? (issuetracker.google.com)](https://issuetracker.google.com/u/0/issues/79189568)
184+
- [Add support for JUnit 5 (issuetracker.google.com)](https://issuetracker.google.com/issues/127100532)
185+
- [JUnit 5 support (github.com/android/android-test)](https://github.com/android/android-test/issues/224)
186+
187+
# Building Locally
188+
189+
This repository contains multiple modules, divided into two sub-projects. The repository's root directory contains build logic shared across the sub-projects, which in turn use symlinks to connect to the common build scripts in their parent folder.
190+
191+
- `instrumentation`: The root folder for Android-based modules, namely the instrumentation libraries & a sample application. After cloning, open this project in Android Studio.
192+
- `plugin`: The root folder for Java-based modules, namely the Gradle plugin for JUnit 5 on Android, as well as its test module. After cloning, open this project in IntelliJ IDEA.
193+
194+
## License
195+
196+
```
197+
Copyright 2017-2019 Marcel Schnelle
198+
199+
Licensed under the Apache License, Version 2.0 (the "License");
200+
you may not use this file except in compliance with the License.
201+
You may obtain a copy of the License at
202+
203+
http://www.apache.org/licenses/LICENSE-2.0
204+
205+
Unless required by applicable law or agreed to in writing, software
206+
distributed under the License is distributed on an "AS IS" BASIS,
207+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
208+
See the License for the specific language governing permissions and
209+
limitations under the License.
210+
```
211+
212+
See also the [full License text](LICENSE).
213+
214+
[junit5gh]: https://github.com/junit-team/junit5
215+
[junit5ug]: https://junit.org/junit5/docs/current/user-guide
216+
[circleci]: https://circleci.com/gh/mannodermaus/android-junit5
217+
[sonatyperepo]: https://oss.sonatype.org/content/repositories/snapshots
218+
[sampletests]: instrumentation/sample
219+
[wiki-dsl]: https://github.com/mannodermaus/android-junit5/wiki/Configuration-DSL
220+
[wiki-gettingstarted]: https://github.com/mannodermaus/android-junit5/wiki/Getting-Started

build.gradle.kts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,21 @@ allprojects {
3232
// Store deployment credentials (used in deployment.gradle)
3333
extra["deployCredentials"] = DeployCredentials(project)
3434
}
35+
36+
tasks.create<GenerateReadme>("generateReadme") {
37+
// Find folder containing README.md
38+
// (required because this script file is included through symlinks in sub-projects)
39+
var rootFolder = project.rootDir
40+
while (rootFolder != null && rootFolder.exists()) {
41+
val inFile = File(rootFolder, "README.md.template")
42+
val outFile = File(rootFolder, "README.md")
43+
44+
if (inFile.exists() && outFile.exists()) {
45+
this.inputTemplateFile = inFile
46+
this.outputFile = outFile
47+
break
48+
}
49+
50+
rootFolder = rootFolder.parentFile
51+
}
52+
}

buildSrc/src/main/kotlin/Artifacts.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ object Artifacts {
3535
platform = Java,
3636
groupId = "de.mannodermaus.gradle.plugins",
3737
artifactId = "android-junit5",
38-
currentVersion = "1.5.1.1-SNAPSHOT",
39-
latestStableVersion = "1.5.0.0",
38+
currentVersion = "1.5.2.0",
39+
latestStableVersion = "1.5.1.0",
4040
license = license,
4141
description = "Unit Testing with JUnit 5 for Android."
4242
)

0 commit comments

Comments
 (0)