Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defaults: &defaults
docker:
- image: circleci/android:api-28-alpha
environment:
GRADLE_OPTS: '-Dorg.gradle.daemon=true -Dorg.gradle.jvmargs="-Xmx3g -XX:+HeapDumpOnOutOfMemoryError"'
GRADLE_OPTS: '-Dorg.gradle.daemon=true -Dorg.gradle.jvmargs="-Xmx4g -XX:+HeapDumpOnOutOfMemoryError"'

cache_key: &cache_key
key: jars-{{ checksum "build.gradle" }}-{{ checksum "android-junit5/build.gradle" }}-{{ checksum "android-junit5-tests/build.gradle" }}-{{ checksum "instrumentation/build.gradle" }}-{{ checksum "instrumentation-runner/build.gradle" }}-{{ checksum "sample/build.gradle" }}-{{ checksum "gradle.properties" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ The latest version of this plugin requires:

## Instrumentation Test Support

There is experimental support for Android instrumentation tests, which requires some additional configuration & dependencies. Note that since JUnit 5 is built on Java 8 from the ground up, these libraries require you to have a `minSdkVersion` of at least `26`.
There is experimental support for Android instrumentation tests, which requires some additional configuration & dependencies. Note that since JUnit 5 is built on Java 8 from the ground up, these libraries require you to have a `minSdkVersion` of at least `26`. It's recommended to use a product flavor for experimentation if you want to keep your global requirements below `26`. Check the sample for how this can be done!

To include the experimental instrumentation test support, add the following to your `build.gradle`:
To start writing instrumentation tests with JUnit Jupiter, add the following to your `build.gradle`:

```groovy
android {
Expand All @@ -67,11 +67,13 @@ android {
}
dependencies {
// (Required) Writing tests for JUnit Jupiter
// Note: Including the Engine as well is not required for instrumentation tests
androidTestImplementation "org.junit.jupiter:junit-jupiter-api:5.2.0"

// (Required) Instrumentation test libraries
// (Required) The instrumentation test companion library
androidTestImplementation "de.mannodermaus.junit5:android-instrumentation-test:0.2.2"

// (Required) Runtime dependencies to orchestrate the execution on-device
androidTestRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.2.0"
androidTestRuntimeOnly "org.junit.platform:junit-platform-runner:1.2.0"
androidTestRuntimeOnly "de.mannodermaus.junit5:android-instrumentation-test-runner:0.2.2"
}
```
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ GITHUB_REPO = mannodermaus/android-junit5
LICENSE_NAME = Apache-2.0

# Artifact configuration (plugin)
PLUGIN_GROUP_ID = de.mannodermaus.gradle.plugins
PLUGIN_ARTIFACT_ID = android-junit5
PLUGIN_DESCRIPTION = Unit Testing with JUnit 5 for Android.
PLUGIN_VERSION_NAME = 1.2.0.1-SNAPSHOT
PLUGIN_VERSION_NAME_LATEST_STABLE = 1.0.32
PLUGIN_GROUP_ID = de.mannodermaus.gradle.plugins
PLUGIN_ARTIFACT_ID = android-junit5
PLUGIN_DESCRIPTION = Unit Testing with JUnit 5 for Android.
PLUGIN_VERSION_NAME = 1.2.0.1-SNAPSHOT
PLUGIN_VERSION_NAME_LATEST_STABLE = 1.2.0.0

# Artifact configuration (instrumentation & runner)
INSTRUMENTATION_GROUP_ID = de.mannodermaus.junit5
Expand Down Expand Up @@ -45,7 +45,7 @@ KOTLIN_VERSION = 1.2.51
COMPILE_SDK_VERSION = android-28
BUILD_TOOLS_VERSION = 27.0.3
TARGET_SDK_VERSION = 28
JAVA_MAX_HEAP_SIZE = 1024m
JAVA_MAX_HEAP_SIZE = 3g

# Android Environment (sample)
SAMPLE_MIN_SDK_VERSION = 14
Expand Down
27 changes: 18 additions & 9 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ android {
versionCode 1
versionName "1.0"

// Make sure to use the AndroidJUnitRunner (or a sub-class) in order to hook in the JUnit 5 Test Builder
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArgument "runnerBuilder", "de.mannodermaus.junit5.AndroidJUnit5Builder"
}

// Since the minSdkVersion requirement for JUnit 5 Instrumentation Tests is quite high,
Expand Down Expand Up @@ -59,10 +61,10 @@ android {

testOptions {
junitPlatform {
details "tree"
platformVersion JUNIT_PLATFORM_VERSION
jupiterVersion JUNIT_JUPITER_VERSION
vintageVersion JUNIT_VINTAGE_VERSION
// Configure JUnit 5 tests here
}
unitTests.all {
testLogging.events = ["passed", "skipped", "failed"]
}
}

Expand All @@ -75,13 +77,20 @@ android {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION"

testImplementation junit5.unitTests()
testImplementation junit5.parameterized()
testImplementation "org.junit.jupiter:junit-jupiter-api:$JUNIT_JUPITER_VERSION"
testImplementation "org.junit.jupiter:junit-jupiter-params:$JUNIT_JUPITER_VERSION"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$JUNIT_JUPITER_VERSION"

androidTestImplementation "junit:junit:$JUNIT4_VERSION"
androidTestImplementation "com.android.support.test:runner:$SUPPORT_TEST_LIBRARY_VERSION"

// Include the instrumentation test dependencies to the product flavor
androidTestExperimentalImplementation junit5.unitTests()
androidTestExperimentalImplementation junit5.instrumentationTests()
// Add the Android Instrumentation Test dependencies to the product flavor only
// (with this, only the "experimental" flavor must have minSdkVersion 26)
androidTestExperimentalImplementation "org.junit.jupiter:junit-jupiter-api:$JUNIT_JUPITER_VERSION"
androidTestExperimentalImplementation "de.mannodermaus.junit5:android-instrumentation-test:$INSTRUMENTATION_VERSION_NAME_LATEST_STABLE"

// Runtime dependencies for Android Instrumentation Tests
androidTestExperimentalRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$JUNIT_JUPITER_VERSION"
androidTestExperimentalRuntimeOnly "org.junit.platform:junit-platform-runner:$JUNIT_PLATFORM_VERSION"
androidTestExperimentalRuntimeOnly "de.mannodermaus.junit5:android-instrumentation-test-runner:$INSTRUMENTATION_VERSION_NAME_LATEST_STABLE"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.mannodermaus.junit5.sample;
package de.mannodermaus.sample;

import java.util.ArrayList;
import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.mannodermaus.junit5.sample
package de.mannodermaus.sample

import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.AfterEach
Expand Down