Releases: mannodermaus/android-junit5
Gradle Plugin: 1.0.22
The next version of our Gradle Plugin brings quite a few deprecations alongside brand-new functionality & fixes! Please read the Migration section carefully to upgrade properly.
New Features
Support for Instrumentation Tests
For the first time, you can run instrumented tests (i.e. on-device tests, driven by frameworks like Espresso) with the JUnit Platform! The plugin can configure your project in a way that enhances the default Test Instrumentation Runner with JUnit 5-based functionality. For the curious, we're currently subject to the same limitations that the JUnit Platform Runner has, so only a subset of JUnit 5 features will work in instrumented tests at this time. It's enough to get started with most things you would need, though, so try it out for yourself!
Instrumented Test Support is disabled by default, since its minSdkVersion
requirement is pretty steep, and the feature itself is still incubating. First, you need to enable it explicitly, then include the junit5.instrumentationTests()
library into your dependencies
block:
android {
testOptions {
junitPlatform {
instrumentationTests.enabled true
}
}
}
dependencies {
androidTestImplementation junit5.instrumentationTests()
}
A User Guide for writing instrumentation tests is coming, so please stay tuned for that.
Fixes
The following issues have been addressed in this version:
- #34 Unable to find method during gradle sync
- #36 Running tests on multiple flavors
- #37 Move junitPlatform configuration into android namespace enhancement
- #38 Delete duplicated Jacoco config, obey the default
Migration
Move the config closure
The junitPlatform
closure added by the plugin has been moved from being a top-level extension, to a new location inside android.testOptions
. This resonates with the canon of the Android Gradle Plugin's testing-related options.
Before
junitPlatform {
jupiterVersion "..."
details "..."
// more here...
}
After
android {
testOptions {
junitPlatform {
jupiterVersion "..."
details "..."
// more here...
}
}
}
Update your dependencies
The JUnit 5 dependency handlers have been refactored yet again. With the addition of support for instrumentation tests, the current set of names didn't feel accurate enough anymore.
Before
testImplementation junit5()
testImplementation junit5Params()
testCompileOnly junit5EmbeddedRuntime()
After
testImplementation junit5.unitTests()
testImplementation junit5.parameterized()
testCompileOnly junit5.unitTestsRuntime()
Review your Jacoco integration
The Jacoco extension has been polished and extended to resemble its respective's plugin a little more.
Before
junitPlatform {
jacoco {
xmlReport true
htmlReport true
csvReport true
}
After
android {
testOptions {
junitPlatform {
jacoco {
xml {
enabled true
destination project.file()
}
html {
enabled true
destination project.file()
}
csv {
enabled true
destination project.file()
}
}
}
}
}
Instrumentation Test Library: 0.1.1
Please welcome the first "real" library release of the Instrumentation Test companion library for JUnit 5! I'm pretty stoked that we finally have an intermediate solution to driving instrumentation tests on Android with the JUnit Platform.
While the User Guide is still in development, here's a small gist of how to use it with the latest Gradle plugin (1.0.22
):
- Update your
minSdkVersion
to 26 or higher - Enable JUnit 5 instrumented tests in the plugin:
android.testOptions { junitPlatform { instrumentationTests.enabled true } }
- Add the dependency on the companion library:
dependencies { androidTestImplementation junit5.instrumentationTests() }
- Create a test class, extend it with
@ActivityTest
and add a parameter of typeTested
to your test methods (optional):@ActivityTest(MyActivity::class) class InstrumentationTests { @Test fun someTest(tested: Tested<MyActivity>) { // Do your assertions (e.g. Espresso, ...) } }
1.0.20
This release brings compatibility with JUnit 5.0.2.
This version replaces the Copy task for Kotlin-based unit tests, which was prevalent in the previous versions of the plugin. Since the IDE integration seems to have improved greatly and Kotlin tests are properly detected from within Android Studio, the requirement to copy over the classes has been lifted. Now, the plugin is configuring JUnit 5 directly to allow these tests to run from the command line via Gradle, as well.
In other news, the plugin is now almost entirely written in Kotlin. The test scope remains in Groovy because of the frameworks in place, but moving to Kotlin for the main portion of the plugin feels great as an outlook forward!
1.0.12
1.0.10
This release brings compatibility with JUnit 5.0.1.
I'm unapologetically copying the Kotlin versioning scheme for this plugin from now on. A four-component semantic version raises a few issues with the existing build tools & IDEs (e.g. when detecting "more recent" versions against SNAPSHOTs), so I'm moving to a three-component version mirroring the JUnit Platform version, and the additional final digit denoting patches inside the plugin itself, unrelated to JUnit advancements.
New
- JaCoCo is now automatically hooked into the JUnit 5 task creation process. The plugin will detect if you also apply the
jacoco
plugin to your project, and configure additional Report tasks accordingly. junit5EmbeddedRuntime()
: A new dependency handler to deal with the Android Studio workaround related to outdated APIs - replace the old explicit artifact (android-junit5-embedded-runtime
) with this and you're good to go.
1.0.0
This release brings compatibility with JUnit 5.0.0.
Breaking Changes
- The deprecated dependency handlers
junitJupiter()
andjunitParams()
have been removed. Please update your Gradle files to usejunit5()
andjunit5Params()
instead.
1.0.0-RC3 Revision 1
The dependency handlers provided by this plugin have been renamed, and the old names deprecated & marked for removal in a future release. The new declarations suit their actual nature better, since they provide more than "just" Jupiter when applied:
Old | Rename To |
---|---|
junitJupiter() |
junit5() |
junitParams() |
junit5Params() |
Also, we can finally run JUnit 5 Tests directly from Android Studio! I've found a workaround to the outdated integration embedded in AS' build of IntelliJ, which allows users to overwrite the JUnit 5-based Launcher of IntelliJ with a more recent version that doesn't use removed APIs. Simply attach the following new dependency to your module:
testCompileOnly "de.mannodermaus.gradle.plugins:android-junit5-embedded-runtime:1.0.0-RC3-rev1"
I hope to be able to deprecate this intermediate library very soon, because Android Studio has to eventually merge the proper branch of the upstream IDEA & obtain compatibility out-of-the-box again. In the meantime, this is a pretty clean solution to running from any IDE.
1.0.0-RC3
This release brings parity with Release Candidate 3 of the JUnit Platform. Most notably, its configurationParameters
are supported through the plugin's DSL, exactly like the Java-based plugin.
Note: This release will be somewhat broken with current builds of Android Studio, up to & including 3.0 Beta 3. If you care about your unit tests running from inside the IDE directly, don't upgrade & stay at M6. See the README for more information on this.
1.0.0-M6
This release brings parity with Milestone 6 of the JUnit Platform, the last iteration before the first official RC of JUnit 5. This is a pretty incremental release without any new features to the Android plugin, so please make sure to read the Platform's release notes to get what's new in the M6 release.
1.0.0-M5
This release brings parity with Milestone 5 of the JUnit Platform. The plugin attempts to further bridge the gap between inconsistencies with bundled versions of JUnit 5 inside IntelliJ IDEA and Android Studio, trying to prevent these nasty NoSuchMethodErrors
when the IDE expects an older milestone at runtime. Otherwise, it's mostly structural niceties which allow for automatic deployment. Also: Snapshots!