Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests on emulator #397

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
52 changes: 51 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,19 @@ jobs:
- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Run app Checks
- name: Run test without shared tests
run: ./gradlew test -Pshared-tests-are-android-tests=false

# - name: Run test with shared tests
# run: ./gradlew test -Pshared-tests-are-android-tests=true

- name: Run test without shared tests
run: ./gradlew assembleAndroidTest -Pshared-tests-are-android-tests=false

# - name: Run test with shared tests
# run: ./gradlew assembleAndroidTest -Pshared-tests-are-android-tests=true

- name: Run check
run: ./gradlew check

- name: Run core Checks
Expand All @@ -55,3 +67,41 @@ jobs:
name: Reports
path: '**/build/reports/*'
retention-days: 2

emulator-tests:
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: '0'

- name: Check out java
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17

- name: Copy CI gradle.properties
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties

- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm

- name: run tests
run: ./gradlew :toggles-app:pixel2api30DebugAndroidTest

- name: "Upload reports"
uses: actions/upload-artifact@v4
if: failure()
with:
name: "Android test results"
path: '**/build/reports/*'
retention-days: 2
6 changes: 4 additions & 2 deletions build-logic/conventions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ java {

dependencies {
// implementation("gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.7.2")
implementation("se.premex:ownership-gradle-plugin:0.0.11")
implementation(libs.se.premex.ownership.gradle.plugin)
implementation(libs.io.gitlab.arturbosch.detekt.detekt.gradle.plugin)
implementation(libs.com.android.tools.build.gradle)
implementation(libs.org.jetbrains.kotlin.kotlin.gradle.plugin)
implementation("com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin:1.9.10-1.0.13")
implementation(libs.com.google.devtools.ksp.com.google.devtools.ksp.gradle.plugin)
implementation(libs.com.squareup.kotlinpoet)
implementation(libs.org.jetbrains.kotlin.compose.compiler.gradle.plugin)

// https://github.com/gradle/gradle/issues/15383
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
Expand Down
13 changes: 10 additions & 3 deletions build-logic/conventions/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rootProject.name="conventions"
rootProject.name = "conventions"

pluginManagement {
repositories {
Expand All @@ -23,6 +23,13 @@ dependencyResolutionManagement {
}

plugins {
id("com.gradle.enterprise") version "3.16.1"
id("org.gradle.toolchains.foojay-resolver-convention") version("0.7.0")
id("com.gradle.develocity") version "3.18"
id("org.gradle.toolchains.foojay-resolver-convention") version ("0.8.0")
}

develocity {
buildScan {
termsOfUseUrl.set("https://gradle.com/help/legal-terms-of-use")
termsOfUseAgree.set("yes")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,70 @@ plugins {
kotlin("android")
id("kotlin-android")
id("toggles.detekt-conventions")
id("org.jetbrains.kotlin.plugin.compose")
}

android {
compileSdk = 34
compileSdk = 35

defaultConfig {
minSdk = 21
targetSdk = 34
targetSdk = 35

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildFeatures {
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = libs.versions.androidx.compose.compiler.get()
}

@Suppress("UnstableApiUsage")
testOptions {
unitTests.isIncludeAndroidResources = true
}

lint {
baseline = file("lint-baseline.xml")
checkReleaseBuilds = true
abortOnError = true
warningsAsErrors = true
lintConfig = File("../lint.xml")
}

testOptions {
animationsDisabled = true
execution = "ANDROIDX_TEST_ORCHESTRATOR"
unitTests {
isReturnDefaultValues = true
isIncludeAndroidResources = true
}
managedDevices {
devices {
maybeCreate<com.android.build.api.dsl.ManagedVirtualDevice>("pixel2api30").apply {
// Use device profiles you typically see in Android Studio.
device = "Pixel 2"
// Use only API levels 30 and higher.
apiLevel = 30
// To include Google services, use "google".
systemImageSource = "aosp"
}
}
}
}

sourceSets {
// val sharedTestDir = "src/sharedTest/"
// if(project.file(sharedTestDir).exists()) {
// val sharedTestSourceDir = sharedTestDir + "java"
// val sharedTestResourceDir = sharedTestDir + "resources"
// val sharedIsAndroid =
// providers.gradleProperty("shared-tests-are-android-tests").get().toBoolean()
// if (sharedIsAndroid) {
// logger.lifecycle("Shared tests are androidTests")
// named("androidTest") {
// java.srcDir(sharedTestSourceDir)
// resources.srcDir(sharedTestResourceDir)
// }
// } else {
// logger.lifecycle("Shared tests are unitTests")
// named("test") {
// java.srcDir(sharedTestSourceDir)
// resources.srcDir(sharedTestResourceDir)
// }
// }
// }
}
}

kotlin {
Expand All @@ -51,4 +83,13 @@ kotlin {

dependencies {
lintChecks(libs.com.slack.lint.compose.compose.lint.checks)

testImplementation(libs.androidx.test.ext.junit)
testImplementation(libs.org.robolectric)
testImplementation(libs.androidx.test.runner)

androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.androidx.test.runner)

androidTestUtil(libs.androidx.test.orchestrator)
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

plugins {
id("com.android.library")
kotlin("android")
id("io.gitlab.arturbosch.detekt")
id("toggles.detekt-library-conventions")

}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,50 @@ android {
warningsAsErrors = true
lintConfig = File("../../lint.xml")
}

testOptions {
animationsDisabled = true
execution = "ANDROIDX_TEST_ORCHESTRATOR"
unitTests {
isReturnDefaultValues = true
isIncludeAndroidResources = true
}
managedDevices {
devices {
maybeCreate<com.android.build.api.dsl.ManagedVirtualDevice>("pixel2api30").apply {
// Use device profiles you typically see in Android Studio.
device = "Pixel 2"
// Use only API levels 30 and higher.
apiLevel = 30
// To include Google services, use "google".
systemImageSource = "aosp"
}
}
}
}

sourceSets {
// val sharedTestDir = "src/sharedTest/"
// if(project.file(sharedTestDir).exists()) {
// val sharedTestSourceDir = sharedTestDir + "java"
// val sharedTestResourceDir = sharedTestDir + "resources"
// val sharedIsAndroid =
// providers.gradleProperty("shared-tests-are-android-tests").get().toBoolean()
// if (sharedIsAndroid) {
// logger.lifecycle("Shared tests are androidTests")
// named("androidTest") {
// java.srcDir(sharedTestSourceDir)
// resources.srcDir(sharedTestResourceDir)
// }
// } else {
// logger.lifecycle("Shared tests are unitTests")
// named("test") {
// java.srcDir(sharedTestSourceDir)
// resources.srcDir(sharedTestResourceDir)
// }
// }
// }
}
}

kotlin {
Expand All @@ -35,4 +79,13 @@ kotlin {

dependencies {
lintChecks(libs.com.slack.lint.compose.compose.lint.checks)

testImplementation(libs.androidx.test.ext.junit)
testImplementation(libs.org.robolectric)
testImplementation(libs.androidx.test.runner)

androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.androidx.test.runner)

androidTestUtil(libs.androidx.test.orchestrator)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

dependencies {
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.22.0")
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.6")
}

detekt {
Expand Down
15 changes: 15 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ buildscript {
}
}

versionCatalogUpdate {
keep {
keepUnusedVersions = true
keepUnusedLibraries = true
keepUnusedPlugins = true
}
}

plugins {
alias(libs.plugins.com.github.ben.manes.versions)
alias(libs.plugins.nl.littlerobots.version.catalog.update)
Expand All @@ -28,6 +36,13 @@ plugins {
alias(libs.plugins.com.autonomousapps.dependency.analysis)
}

develocity {
buildScan {
termsOfUseUrl.set("https://gradle.com/help/legal-terms-of-use")
termsOfUseAgree.set("yes")
}
}

fun isNonStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any {
version.uppercase(Locale.getDefault()).contains(it)
Expand Down
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2g -Xms500m -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx12120m

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
Expand Down Expand Up @@ -42,3 +42,5 @@ android.enableJetifier=false
org.gradle.caching=true
org.gradle.configuration-cache=true
org.gradle.configuration-cache.max-problems=5

shared-tests-are-android-tests=true
Loading
Loading