Skip to content

Commit

Permalink
Migrates Android UI Tests to Robolectric-Instrumented Unit-Tests and …
Browse files Browse the repository at this point in the history
…adds Coverage Reports (#21)

* Migrates tests from android UI tests to instrumented unit tests

* Adds coverage reporting and moves plugin-definition to version catalog

* Drop unnecessary strategy for gha action

* Setup-java 17

* Adds codecov badge
  • Loading branch information
mattsilber authored Dec 15, 2023
1 parent 6c81716 commit 09bafc6
Show file tree
Hide file tree
Showing 18 changed files with 135 additions and 89 deletions.
50 changes: 0 additions & 50 deletions .github/workflows/run_tests.yml

This file was deleted.

65 changes: 65 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Test

on:
push:
branches:
- main
pull_request:

jobs:
unit_test:
name: Run Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]

- uses: actions/[email protected]
with:
distribution: 'zulu'
java-version: 17

- name: Cache Gradle Files
uses: actions/[email protected]
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}

- name: Run Unit Tests
run: ./gradlew scratchoff:testDebugUnitTest

- name: Evaluate Test Report
uses: mikepenz/[email protected]
if: always()
with:
report_paths: 'scratchoff/build/test-results/testDebugUnitTest/TEST-*.xml'

- name: Generate Coverage Report
run: ./gradlew scratchoff:koverXmlReportDebug --stacktrace

- name: Store Coverage Artifact
uses: actions/[email protected]
with:
name: Test-Coverage
path: scratchoff/build/reports/kover/reportDebug.xml

report_test_coverage:
needs: unit_test
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/[email protected]

- uses: actions/[email protected]
with:
name: Test-Coverage

- uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: reportDebug.xml
flags: unit
fail_ci_if_error: true
verbose: true
17 changes: 6 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@ buildscript {
ext {
targetSdkVersion = 34
buildToolsVersion = "34.0.0"
kotlinVersion = "1.9.21"
}

repositories {
maven { url "https://maven.google.com/" }
mavenCentral()
gradlePluginPortal()
}
}

dependencies {
classpath "com.android.tools.build:gradle:8.2.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
plugins {
alias(libs.plugins.kotlinAndroid) apply false
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.androidLibrary) apply false
alias(libs.plugins.kover) apply true
}

allprojects {
Expand Down
12 changes: 12 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[versions]
agp = "8.2.0"
kotlin = "1.9.21"
kover = "0.7.5"

[libraries]

[plugins]
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
androidApplication = { id = "com.android.application", version.ref = "agp" }
androidLibrary = { id = "com.android.library", version.ref = "agp" }
kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" }
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Scratchoff

[![Download](https://img.shields.io/maven-central/v/com.jackpocket/scratchoff)](https://search.maven.org/artifact/com.jackpocket/scratchoff)
[![Download](https://img.shields.io/maven-central/v/com.jackpocket/scratchoff)](https://search.maven.org/artifact/com.jackpocket/scratchoff) [![codecov](https://codecov.io/gh/jackpocket/android-scratchoff/graph/badge.svg?token=bLQlZ7Rh8x)](https://codecov.io/gh/jackpocket/android-scratchoff)

A simple library for implementing scratchable Views.

Expand Down
11 changes: 6 additions & 5 deletions scratchoff-sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.kotlinAndroid)
}

android {
namespace "com.jackpocket.scratchoff.test"
Expand All @@ -17,6 +19,8 @@ android {
versionName "1.0.0"

vectorDrawables.useSupportLibrary = true

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
Expand All @@ -35,8 +39,5 @@ android {
dependencies {
implementation project(path: ':scratchoff')

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
implementation "androidx.appcompat:appcompat:1.3.1"

testImplementation "junit:junit:4.13.2"
}
35 changes: 28 additions & 7 deletions scratchoff/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
plugins {
alias(libs.plugins.androidLibrary)
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.kover)
}

android {
namespace "com.jackpocket.scratchoff"
Expand All @@ -8,7 +11,7 @@ android {
buildToolsVersion = rootProject.ext.buildToolsVersion

defaultConfig {
minSdkVersion 9
minSdkVersion 14
targetSdkVersion rootProject.ext.targetSdkVersion

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -20,13 +23,31 @@ android {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

testOptions {
unitTests {
includeAndroidResources = true
returnDefaultValues = true
}
}
}

dependencies {
androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
androidTestImplementation "androidx.test.ext:junit:1.1.3"
androidTestImplementation "androidx.test:runner:1.4.0"
androidTestImplementation "androidx.test:core:1.4.0"
testImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${libs.versions.kotlin.get()}"
testImplementation "androidx.test.ext:junit:1.1.5"
testImplementation "androidx.test:runner:1.5.2"
testImplementation "androidx.test:core:1.5.0"
testImplementation "org.robolectric:robolectric:4.11.1"
}

kover {
instrumentation {
excludeTasks.addAll(
[
"testReleaseUnitTest",
]
)
}
}

apply from: "./publishing.gradle"
15 changes: 0 additions & 15 deletions scratchoff/src/androidTest/AndroidManifest.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import com.jackpocket.scratchoff.views.ScratchableLinearLayout
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.annotation.GraphicsMode

@RunWith(AndroidJUnit4::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
class ScratchableLayoutDrawerTests {

private val context: Context by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package com.jackpocket.scratchoff
import android.os.Parcel
import android.view.AbsSavedState
import android.view.MotionEvent
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.jackpocket.scratchoff.paths.ScratchPathPoint
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class ScratchoffStateTests {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import com.jackpocket.scratchoff.tools.ThresholdCalculator
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.annotation.GraphicsMode

@RunWith(AndroidJUnit4::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
class ScratchoffThresholdProcessorTests {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import com.jackpocket.scratchoff.ScratchoffThresholdProcessor
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.annotation.GraphicsMode

@RunWith(AndroidJUnit4::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
class ThresholdCalculatorTests {

@Test
Expand Down
8 changes: 8 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
pluginManagement {
repositories {
mavenCentral()
maven { url "https://maven.google.com/" }
gradlePluginPortal()
}
}

include ':scratchoff', ':scratchoff-sample'

0 comments on commit 09bafc6

Please sign in to comment.