Skip to content

Commit

Permalink
build: Change java version to 17 for robolectric-extension tests (#83)
Browse files Browse the repository at this point in the history
- adding an integration test to test with java 11
  • Loading branch information
warnyul authored Aug 5, 2024
1 parent 488468c commit b816ee7
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .idea/gradle.xml

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

1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ subprojects {
dependencies {
kover(project(':integration-tests:agp-groovy-dsl'))
kover(project(':integration-tests:agp-kotlin-dsl'))
kover(project(':integration-tests:java-11'))
kover(project(':robolectric-extension'))
kover(project(':robolectric-extension-gradle-plugin'))
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
androidBuildTools = "34.0.0"
androidToolsCommon = "31.5.1"
androidCompileSdk = "34"
androidCompileSdkJava11 = "33"
androidGradle = "8.5.1"
androidMinimumSdk = "19"
androidxTestExtJunit = "1.2.1"
Expand All @@ -23,7 +24,6 @@ sources = "sources"

[libraries]
androidGradleApi = { module = "com.android.tools.build:gradle-api", version.ref = "androidGradle" }
androidGradle = { module = "com.android.tools.build:gradle", version.ref = "androidGradle" }
androidGradleJava11 = { module = "com.android.tools.build:gradle", version = { require = "[7.0.0,8.0.0[", prefer = "7.4.2" } }
androidToolsCommon = { module = "com.android.tools:common", version.ref = "androidToolsCommon" }
androidxTestExtJunit = { module = "androidx.test.ext:junit", version.ref = "androidxTestExtJunit" }
Expand Down
37 changes: 37 additions & 0 deletions integration-tests/java-11/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
plugins {
alias(libs.plugins.androidLibrary)
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.kotlinxKover)
alias(libs.plugins.detekt)
alias(libs.plugins.robolectricExtensionGradlePlugin)
}

android {
namespace = 'tech.apter.junit.jupiter.robolectric.integration.tests.agp.groovy.dsl'
compileSdk = libs.versions.androidCompileSdkJava11.get().toInteger()
buildToolsVersion = libs.versions.androidBuildTools.get()

defaultConfig {
minSdk = libs.versions.androidMinimumSdk.get().toInteger()
}

testOptions {
unitTests.all { Test test ->
test.systemProperty('robolectric.enabledSdks', '19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33')
}
}
}

detekt {
toolVersion = libs.versions.detekt.get()
autoCorrect = true
}

kotlin {
jvmToolchain(libs.versions.jvmToolchainMin.get().toInteger())
}

dependencies {
detektPlugins(libs.detektFormatting)
detektPlugins(libs.detektRulesLibraries)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package tech.apter.junit.jupiter.robolectric.integration.tests.java11

import android.os.Build
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import tech.apter.junit.jupiter.robolectric.RobolectricExtension

@ExtendWith(RobolectricExtension::class)
@Config(sdk = [Build.VERSION_CODES.TIRAMISU])
class Java11Test {
@Test
fun `Given an android project with kotlin-dsl build script when using Robolectric with JUnit5 the android app should be available`() {
assertNotNull(RuntimeEnvironment.getApplication())
}
}
8 changes: 8 additions & 0 deletions robolectric-extension/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ test {
systemProperty 'robolectric.usePreinstrumentedJars', 'true'
}

tasks.test {
javaLauncher.set(
javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(libs.versions.jvmToolchain.get().toInteger()))
}
)
}

detekt {
toolVersion = libs.versions.detekt.get()
autoCorrect true
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencyResolutionManagement {
rootProject.name = 'junit5-robolectric-extension'
include('integration-tests:agp-groovy-dsl')
include('integration-tests:agp-kotlin-dsl')
include('integration-tests:java-11')
include('robolectric-extension')
include('robolectric-extension-gradle-plugin')

0 comments on commit b816ee7

Please sign in to comment.