Skip to content

Commit

Permalink
Update build env, dependencies, minimum AGP/Gradle versions
Browse files Browse the repository at this point in the history
  • Loading branch information
mannodermaus committed Apr 9, 2024
1 parent 41891f8 commit ef0e6c7
Show file tree
Hide file tree
Showing 45 changed files with 402 additions and 287 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ jobs:
name: (Plugin) Build & Deploy
command: |
cd plugin
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository --stacktrace
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepositories --stacktrace
- run:
name: (Instrumentation) Build & Deploy
command: |
cd instrumentation
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository --stacktrace
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepositories --stacktrace
- store_artifacts:
path: plugin/android-junit5/build/publications
destination: plugin/publications/snapshots
Expand Down
18 changes: 16 additions & 2 deletions README.md.template
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,35 @@ Then, add the integration library for Jetpack Compose to the `androidTestImpleme

[The wiki][wiki-home] includes a section on how to test your Composables with JUnit 5.

# Official Support
## Official Support

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:

- [InstantTaskExecutorRule uses @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) -- why? (issuetracker.google.com)](https://issuetracker.google.com/u/0/issues/79189568)
- [Add support for JUnit 5 (issuetracker.google.com)](https://issuetracker.google.com/issues/127100532)
- [JUnit 5 support (github.com/android/android-test)](https://github.com/android/android-test/issues/224)

# Building Locally
## Building Locally

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.

- `instrumentation`: The root folder for Android-based modules, namely the instrumentation libraries & a sample application. After cloning, open this project in Android Studio.
- `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.

## Plugin Compatibility Map

For users that cannot match the current minimum version requirement of the Android Gradle Plugin requested by this plugin,
refer to the table below to find a suitable alternative version. Note that **no active development will go into these
legacy versions**, so please consider upgrading to at least Android Gradle Plugin ${constants.minimumRequiredAgpVersion}
before filing an issue with the latest one.

|Your AGP Version|Suggested JUnit5 Plugin Version|
|---|---|
|`7.0.0` - `7.4.2`|`1.10.0.0`|
|`4.0.0` - `4.2.2`|`1.8.2.1`|
|`3.5.0` - `3.6.4`|`1.7.1.1`|
|`< 3.5.0`|none; you should **really** update your build env, bro|

## License

```
Expand Down
57 changes: 36 additions & 21 deletions build-logic/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,36 @@

object libs {
object versions {
const val kotlin = "1.8.21"
const val junitJupiter = "5.10.0"
const val junitVintage = "5.10.0"
const val junitPlatform = "1.10.0"
const val truth = "1.1.3"
const val androidXTest = "1.4.0"
const val composeCompiler = "1.4.7"
const val composeBom = "2023.05.01"
const val kotlin = "1.9.23"
const val junitJupiter = "5.10.2"
const val junitVintage = "5.10.2"
const val junitPlatform = "1.10.2"

const val composeBom = "2024.04.00"
const val androidXTest = "1.5.0"
const val composeCompiler = "1.5.11"

const val activityCompose = "1.8.2"
const val apiGuardian = "1.1.2"
const val coroutines = "1.8.0"
const val dokka = "1.9.20"
const val espresso = "3.5.1"
const val javaSemver = "0.10.2"
const val junit4 = "4.13.2"
const val konfToml = "1.1.2"
const val korte = "2.4.12"
const val mockitoCore = "5.11.0"
const val mockitoKotlin = "5.2.1"
const val robolectric = "4.12"
const val shadow = "8.1.1"
const val truth = "1.4.2"
}

object plugins {
fun android(version: SupportedAgp) = "com.android.tools.build:gradle:${version.version}"
const val kotlin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${libs.versions.kotlin}"
const val shadow = "com.github.jengelman.gradle.plugins:shadow:6.1.0"
const val dokka = "org.jetbrains.dokka:dokka-gradle-plugin:1.7.0"
const val shadow = "com.github.johnrengelman:shadow:${libs.versions.shadow}"
const val dokka = "org.jetbrains.dokka:dokka-gradle-plugin:${libs.versions.dokka}"
}

// Libraries
Expand All @@ -29,38 +44,38 @@ object libs {
}

const val kotlinStdLib = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}"
const val kotlinCoroutinesCore = "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
const val javaSemver = "com.github.zafarkhaja:java-semver:0.9.0"
const val kotlinCoroutinesCore = "org.jetbrains.kotlinx:kotlinx-coroutines-core:${versions.coroutines}"
const val javaSemver = "com.github.zafarkhaja:java-semver:${versions.javaSemver}"

const val junitJupiterApi = "org.junit.jupiter:junit-jupiter-api:${versions.junitJupiter}"
const val junitJupiterParams = "org.junit.jupiter:junit-jupiter-params:${versions.junitJupiter}"
const val junitJupiterEngine = "org.junit.jupiter:junit-jupiter-engine:${versions.junitJupiter}"
const val junitVintageEngine = "org.junit.vintage:junit-vintage-engine:${versions.junitVintage}"
const val junitPlatformCommons = "org.junit.platform:junit-platform-commons:${versions.junitPlatform}"
const val junitPlatformRunner = "org.junit.platform:junit-platform-runner:${versions.junitPlatform}"
const val apiguardianApi = "org.apiguardian:apiguardian-api:1.1.2"
const val apiguardianApi = "org.apiguardian:apiguardian-api:${versions.apiGuardian}"

const val composeBom = "androidx.compose:compose-bom:${versions.composeBom}"
const val composeUi = "androidx.compose.ui:ui"
const val composeUiTooling = "androidx.compose.ui:ui-tooling"
const val composeFoundation = "androidx.compose.foundation:foundation"
const val composeMaterial = "androidx.compose.material:material"
const val composeActivity = "androidx.activity:activity-compose:1.7.1"
const val composeActivity = "androidx.activity:activity-compose:${versions.activityCompose}"

// Testing
const val junit4 = "junit:junit:4.13.2"
const val korte = "com.soywiz.korlibs.korte:korte:2.2.0"
const val konfToml = "com.uchuhimo:konf-toml:1.1.2"
const val mockitoCore = "org.mockito:mockito-core:3.11.1"
const val mockitoKotlin = "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
const val junit4 = "junit:junit:${versions.junit4}"
const val korte = "com.soywiz.korlibs.korte:korte:${versions.korte}"
const val konfToml = "com.uchuhimo:konf-toml:${versions.konfToml}"
const val mockitoCore = "org.mockito:mockito-core:${versions.mockitoCore}"
const val mockitoKotlin = "org.mockito.kotlin:mockito-kotlin:${versions.mockitoKotlin}"
const val truth = "com.google.truth:truth:${versions.truth}"
const val truthJava8Extensions = "com.google.truth.extensions:truth-java8-extension:${versions.truth}"
const val robolectric = "org.robolectric:robolectric:4.8.1"
const val robolectric = "org.robolectric:robolectric:${versions.robolectric}"

const val androidXTestCore = "androidx.test:core:${versions.androidXTest}"
const val androidXTestRunner = "androidx.test:runner:${versions.androidXTest}"
const val androidXTestMonitor = "androidx.test:monitor:${versions.androidXTest}"
const val espressoCore = "androidx.test.espresso:espresso-core:3.4.0"
const val espressoCore = "androidx.test.espresso:espresso-core:${versions.espresso}"

const val composeUiTest = "androidx.compose.ui:ui-test"
const val composeUiTestJUnit4 = "androidx.compose.ui:ui-test-junit4"
Expand Down
12 changes: 4 additions & 8 deletions build-logic/src/main/kotlin/Environment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ enum class SupportedAgp(
val version: String,
val gradle: String? = null
) {
AGP_7_0("7.0.4", gradle = "7.0.2"),
AGP_7_1("7.1.3", gradle = "7.2"),
AGP_7_2("7.2.2", gradle = "7.3.3"),
AGP_7_3("7.3.1", gradle = "7.4.2"),
AGP_7_4("7.4.2", gradle = "7.5.1"),
AGP_8_0("8.0.2", gradle = "8.0"),
AGP_8_1("8.1.4", gradle = "8.0"),
AGP_8_2("8.2.2", gradle = "8.2"),
Expand All @@ -22,6 +17,7 @@ enum class SupportedAgp(

companion object {
val oldest = values().first()
val newestStable = values().reversed().first { '-' !in it.version }
}

val shortVersion: String = run {
Expand All @@ -38,9 +34,9 @@ enum class SupportedAgp(
}

object Android {
const val compileSdkVersion = 33
const val targetSdkVersion = 32
const val sampleMinSdkVersion = 14
const val compileSdkVersion = 34
const val targetSdkVersion = 34
const val sampleMinSdkVersion = 21
val testRunnerMinSdkVersion = (Artifacts.Instrumentation.Runner.platform as Android).minSdk
val testCoreMinSdkVersion = (Artifacts.Instrumentation.Core.platform as Android).minSdk
val testComposeMinSdkVersion = (Artifacts.Instrumentation.Compose.platform as Android).minSdk
Expand Down
2 changes: 1 addition & 1 deletion build-logic/src/main/kotlin/Tasks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import java.io.File
import java.time.ZonedDateTime
import java.util.*

private const val minimumGradleVersion = "7.0"
private const val minimumGradleVersion = "8.0"

@Suppress("DEPRECATION")
fun Project.configureTestResources() {
Expand Down
7 changes: 3 additions & 4 deletions instrumentation/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
id("io.github.gradle-nexus.publish-plugin").version("1.1.0")
id("com.github.ben-manes.versions").version("0.42.0")
id("org.jetbrains.kotlinx.binary-compatibility-validator").version("0.11.0")
id("io.github.gradle-nexus.publish-plugin").version("2.0.0")
id("org.jetbrains.kotlinx.binary-compatibility-validator").version("0.14.0")
}

buildscript {
Expand All @@ -15,7 +14,7 @@ buildscript {
dependencies {
classpath(libs.plugins.kotlin)
classpath(libs.plugins.dokka)
classpath(libs.plugins.android(SupportedAgp.oldest))
classpath(libs.plugins.android(SupportedAgp.newestStable))
}
}

Expand Down
9 changes: 7 additions & 2 deletions instrumentation/compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ plugins {
val javaVersion = JavaVersion.VERSION_11

android {
namespace = "de.mannodermaus.junit5.compose"
compileSdk = Android.compileSdkVersion

defaultConfig {
minSdk = Android.testComposeMinSdkVersion
targetSdk = Android.targetSdkVersion

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments["runnerBuilder"] = "de.mannodermaus.junit5.AndroidJUnit5Builder"
Expand All @@ -42,9 +42,14 @@ android {

testOptions {
unitTests.isReturnDefaultValues = true
targetSdk = Android.targetSdkVersion
}

lint {
targetSdk = Android.targetSdkVersion
}

packagingOptions {
packaging {
resources.excludes.add("META-INF/AL2.0")
resources.excludes.add("META-INF/LGPL2.1")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.mannodermaus.junit5.compose">

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<activity android:name=".ExistingActivity" />
</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue

class ExistingActivity : ComponentActivity() {
public class ExistingActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContent {
Column {
var counter by remember { mutableStateOf(0) }
var counter by remember { mutableIntStateOf(0) }

Text(text = "Clicked: $counter")
Button(onClick = { counter++ }) {
Expand Down
1 change: 0 additions & 1 deletion instrumentation/compose/src/main/AndroidManifest.xml

This file was deleted.

10 changes: 6 additions & 4 deletions instrumentation/core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ plugins {
id("de.mannodermaus.android-junit5").version(Artifacts.Plugin.latestStableVersion)
}

val javaVersion = JavaVersion.VERSION_1_8
val javaVersion = JavaVersion.VERSION_11

android {
namespace = "de.mannodermaus.junit5"
compileSdk = Android.compileSdkVersion

defaultConfig {
minSdk = Android.testCoreMinSdkVersion
targetSdk = Android.targetSdkVersion
multiDexEnabled = true

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -35,16 +35,18 @@ android {

lint {
// JUnit 4 refers to java.lang.management APIs, which are absent on Android.
warning("InvalidPackage")
warning.add("InvalidPackage")
targetSdk = Android.targetSdkVersion
}

packagingOptions {
packaging {
resources.excludes.add("META-INF/LICENSE.md")
resources.excludes.add("META-INF/LICENSE-notice.md")
}

testOptions {
unitTests.isReturnDefaultValues = true
targetSdk = Android.targetSdkVersion
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.Extension;
import org.junit.jupiter.api.extension.ExtensionContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.mannodermaus.junit5">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<activity android:name=".TestActivity"/>
</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package de.mannodermaus.junit5
import android.app.Activity
import android.os.Bundle
import android.widget.TextView
import de.mannodermaus.junit5.test.R

class TestActivity : Activity() {

Expand Down
1 change: 0 additions & 1 deletion instrumentation/core/src/main/AndroidManifest.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package de.mannodermaus.junit5.condition

import com.google.common.truth.Truth8.assertThat
import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.whenever
import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.TestInfo
import org.junit.jupiter.api.extension.ConditionEvaluationResult
import org.junit.jupiter.api.extension.ExecutionCondition
import org.junit.jupiter.api.extension.ExtensionContext
import org.junit.platform.commons.util.ReflectionUtils
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever
import java.lang.reflect.AnnotatedElement
import java.util.*

Expand Down
10 changes: 6 additions & 4 deletions instrumentation/extensions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ apply {
plugin("de.mannodermaus.android-junit5")
}

val javaVersion = JavaVersion.VERSION_1_8
val javaVersion = JavaVersion.VERSION_11

android {
namespace = "de.mannodermaus.junit5.extensions"
compileSdk = Android.compileSdkVersion

defaultConfig {
minSdk = Android.testRunnerMinSdkVersion
targetSdk = Android.targetSdkVersion
}

compileOptions {
Expand All @@ -48,16 +48,18 @@ android {

lint {
// JUnit 4 refers to java.lang.management APIs, which are absent on Android.
warning("InvalidPackage")
warning.add("InvalidPackage")
targetSdk = Android.targetSdkVersion
}

packagingOptions {
packaging {
resources.excludes.add("META-INF/LICENSE.md")
resources.excludes.add("META-INF/LICENSE-notice.md")
}

testOptions {
unitTests.isReturnDefaultValues = true
targetSdk = Android.targetSdkVersion
}
}

Expand Down
1 change: 0 additions & 1 deletion instrumentation/extensions/src/main/AndroidManifest.xml

This file was deleted.

Loading

0 comments on commit ef0e6c7

Please sign in to comment.