Skip to content

Commit

Permalink
Fix main (#119)
Browse files Browse the repository at this point in the history
* WiP, trying to get test filtering to work

* added test filtering

* Fixed issue with multiple devices, tags for tests

* lint fixes

* update agp

* agp -> 8.0.1

* just run instrumented tests without coverage until fixed

* docker container doesn't have jdk-17 on it

* forgot to bump to jdk 17

* fixed coverage reports
  • Loading branch information
compscidr committed May 12, 2023
1 parent 30676cf commit 462577f
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 41 deletions.
28 changes: 12 additions & 16 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ jobs:
with:
fetch-depth: 0
clean: true
# not needed because using a self-hosted runner with jdk and android already on it:
# https://github.com/compscidr/docker-github-actions-runner-android
# - name: Set up JDK
# uses: actions/setup-java@v3
# with:
# java-version: 11
# distribution: temurin
# - name: Setup Android SDK
# uses: android-actions/setup-android@v2
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: 17
distribution: temurin
- name: Setup Android SDK
uses: android-actions/setup-android@v2
- name: Build with Gradle
run: ./gradlew clean build --no-build-cache
- name: lint
Expand All @@ -31,12 +29,10 @@ jobs:
report-path: app/build/reports/lint/report.xml
- name: Jvm Unit Tests with Coverage Report
run: ./gradlew jacocoTestReportDebug
- name: On-Device Instrumented Tests with CoverageReport
run: |
timeout 10 adb wait-for-device &&
adb uninstall --user 0 com.example.myapplication || true &&
adb uninstall --user 0 com.example.myapplication.test || true &&
./gradlew coverageReport
- name: Clean Packages
run: bash ./scripts/clean-packages.sh
- name: On-Device Instrumented Tests
run: ./gradlew connectedCheck
- uses: actions/upload-artifact@v3
name: Store Reporting Artifacts
if: failure()
Expand Down Expand Up @@ -64,7 +60,7 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: instrumentedtests
files: ./app/build/reports/jacoco.xml
files: ./app/build/reports/coverage/androidTest/debug/connected/report.xml

- name: Export environment variables
run: |
Expand Down
35 changes: 24 additions & 11 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ plugins {
id 'io.github.reactivecircus.app-versioning' version '1.1.2'
id 'de.mannodermaus.android-junit5'
id 'org.jmailen.kotlinter'
id 'org.jetbrains.dokka'
id 'jacoco'
//id 'org.jetbrains.dokka'
}

android {
namespace "com.example.myapplication"
compileSdkVersion 33
buildToolsVersion "30.0.3"
defaultConfig {
testInstrumentationRunnerArguments runnerBuilder: 'de.mannodermaus.junit5.AndroidJUnit5Builder'
applicationId "com.example.myapplication"
minSdkVersion 16
targetSdkVersion 33
Expand All @@ -24,20 +26,24 @@ android {
// 1) Make sure to use the AndroidJUnitRunner, of a subclass of it. This requires a dependency on androidx.test:runner, too!
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
// 2) Connect JUnit 5 to the runner
testInstrumentationRunnerArgument("runnerBuilder", "de.mannodermaus.junit5.AndroidJUnit5Builder")
}

// 3) Java 8 is required
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}

// 4) JUnit 5 will bundle in files with identical paths; exclude them
packagingOptions {
exclude("META-INF/LICENSE*")
jniLibs {
excludes += ['META-INF/LICENSE*']
}
resources {
excludes += ['META-INF/LICENSE*']
}
}

// 4) JUnit 5 will bundle in files with identical paths; exclude them

buildTypes {
release {
shrinkResources true
Expand All @@ -55,7 +61,19 @@ android {
useJUnitPlatform()
jacoco {
includeNoLocationClasses = true
excludes = ['jdk.internal.*']
excludes = [
'jdk.internal.*',
]
}
}
// should let the tests run with with gradle via -DincludeTags="tag1,tag2" -DexcludeTags="tag3,tag4"
// https://github.com/mannodermaus/android-junit5/wiki/Configuration
// https://junit.org/junit5/docs/current/user-guide/#writing-tests-tagging-and-filtering
// https://www.vogella.com/tutorials/AndroidTesting/article.html
junitPlatform {
filters {
//includeTags 'TEST1'
//excludeTags 'TEST2'
}
}
// should let the tests run with with gradle via -DincludeTags="tag1,tag2" -DexcludeTags="tag3,tag4"
Expand Down Expand Up @@ -138,11 +156,6 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
}
}

rootCoverage {
includeAndroidTestResults true
generateXml true
}

// https://github.com/ReactiveCircus/app-versioning
appVersioning {
overrideVersionCode { gitTag, providers, variantInfo ->
Expand Down
10 changes: 5 additions & 5 deletions app/publish.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// https://proandroiddev.com/android-libraries-on-github-packages-21f135188d58
apply plugin: 'maven-publish'

task sourceJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier "sources"
}
//task sourceJar(type: Jar) {
// from android.sourceSets.main.java.srcDirs
// classifier "sources"
//}

publishing {
repositories {
Expand All @@ -28,7 +28,7 @@ publishing {
version System.getenv('VERSION_NAME')+"-"+System.getenv('VERSION_CODE')
artifact("$buildDir/outputs/apk/release/app-release-unsigned.apk")
artifact("$buildDir/outputs/bundle/release/app-release.aab")
artifact(sourceJar)
//artifact(sourceJar)

pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.example.myapplication
import androidx.test.platform.app.InstrumentationRegistry
import de.mannodermaus.junit5.ActivityScenarioExtension
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Timeout
import org.junit.jupiter.api.extension.RegisterExtension
Expand All @@ -24,8 +23,8 @@ class ExampleInstrumentedTest {
MainActivity::class.java
)

// @Tag("TEST1") // tags broken: https://github.com/mannodermaus/android-junit5/issues/298
@Test
@Tag("OTHERTEST")
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
Expand All @@ -35,9 +34,15 @@ class ExampleInstrumentedTest {
scenario.onActivity { }
}

// @Tag("TEST2")
@Test
@Tag("TAGTEST")
fun test2() {
logger.debug("test2")
}

// @Tag("TEST3")
@Test
fun test3() {
logger.debug("test3")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.myapplication

import org.junit.jupiter.api.Test
import org.slf4j.LoggerFactory

class SomeOtherTaggedTest {
private val logger = LoggerFactory.getLogger(javaClass)

// @Tag("OTHERTEST")
@Test
fun test() {
logger.debug("SomeOtherTaggedTest")
}
}
9 changes: 4 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

buildscript {
ext {
agp_version = '7.3.1'
kotlin_version = '1.8.10'
agp_version = '8.0.1'
kotlin_version = '1.8.21'
hilt_version = '2.45'
jupiter_version = '5.9.3'
slf4j_version = '2.0.7'
Expand All @@ -19,17 +19,16 @@ buildscript {
dependencies {
classpath "com.android.tools.build:gradle:$agp_version"
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
classpath "de.mannodermaus.gradle.plugins:android-junit5:1.8.2.1"
classpath "de.mannodermaus.gradle.plugins:android-junit5:1.9.3.0"
classpath "org.jmailen.gradle:kotlinter-gradle:3.13.0"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$kotlin_version"
//classpath "org.jetbrains.dokka:dokka-gradle-plugin:$kotlin_version"
}
}

plugins {
id "com.android.application" version "$agp_version" apply false
id "org.jetbrains.kotlin.android" version "$kotlin_version" apply false
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version"
id "nl.neotech.plugin.rootcoverage" version '1.6.0'
id "org.jetbrains.kotlin.jvm" version "$kotlin_version" apply false
}

Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ android.useAndroidX=true
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
9 changes: 9 additions & 0 deletions scripts/clean-packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e

for DEVICE in $(adb devices | sed '1d' | sed '$d' | awk '{print $1}'); do
timeout 20 adb -s $DEVICE wait-for-device
for i in $(adb -s $DEVICE shell pm list packages -f | grep com.example.myapplication | sed -n 's/^.*\/base.apk=//p'); do
adb -s $DEVICE uninstall --user 0 $i
done
done

0 comments on commit 462577f

Please sign in to comment.