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

Prototyping com.android.test module and shared tests in a com.android.lib module. #76

Merged
merged 7 commits into from
Mar 14, 2024
Merged
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
28 changes: 14 additions & 14 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
run: ./gradlew check -Pkmp4free=false -Pios=false -Pjs=false --scan --stacktrace

- name: Run All Checks with Multiplatform - KMP4FREE Enabled
run: ./gradlew check -Pkmp4free=true -Pios=true -Pjs=true --scan --stacktrace
run: ./gradlew check -Pkmp4free=true -Pios=true -Pjs=true --scan --stacktrace --rerun-tasks

- name: (Fail-only) Bundle test reports
if: failure()
Expand Down Expand Up @@ -86,16 +86,16 @@ jobs:
java-version: '17'
check-latest: true

- name: Instrumentation Tests
uses: reactivecircus/android-emulator-runner@6b0df4b0efb23bb0ec63d881db79aefbc976e4b2 # v2
with:
api-level: ${{ matrix.api-level }}
target: default
arch: x86_64
script: ./gradlew connectedCheck --no-build-cache --no-daemon --stacktrace

- name: Upload results
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4
with:
name: insrumentation-test-results
path: ./**/build/reports/androidTests/connected/**
# - name: Instrumentation Tests
# uses: reactivecircus/android-emulator-runner@6b0df4b0efb23bb0ec63d881db79aefbc976e4b2 # v2
# with:
# api-level: ${{ matrix.api-level }}
# target: default
# arch: x86_64
# script: ./gradlew connectedCheck --no-build-cache --no-daemon --stacktrace
#
# - name: Upload results
# uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4
# with:
# name: insrumentation-test-results
# path: ./**/build/reports/androidTests/connected/**
37 changes: 37 additions & 0 deletions app-test-host/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
plugins {
id 'com.android.test'
id 'kotlin-android'
}

android {
compileSdk = Integer.parseInt(libs.versions.android.compile.sdk.get())

defaultConfig {
minSdkVersion Integer.parseInt(libs.versions.android.min.sdk.get())
targetSdkVersion Integer.parseInt(libs.versions.android.target.sdk.get())
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}

namespace = "com.handstandsam.shoppingapp.android.tests"

targetProjectPath = ":app"

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
}

dependencies {
compileOnly(project(":app"))

implementation libs.androidx.espresso
implementation libs.androidx.espresso.contrib
implementation libs.androidx.test.rules
implementation libs.androidx.testrunner
implementation(project(":app-test-suite"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.handstandsam.shoppingapp.tests

import androidx.lifecycle.Lifecycle
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.typeText
import androidx.test.espresso.matcher.ViewMatchers.withId
import com.handstandsam.shoppingapp.R
import com.handstandsam.shoppingapp.features.login.LoginActivity
import org.junit.Assert.assertTrue
import org.junit.Test

/**
* com.android.test
*/
class AndroidTestModuleTest {

@Test
fun androidTestModule() {
assertTrue(true)
}

@Test
fun androidTestModuleLoginActivityTypeUsernameTest() {
val activityScenario: ActivityScenario<LoginActivity> =
ActivityScenario.launch(LoginActivity::class.java)

activityScenario.moveToState(Lifecycle.State.RESUMED)

onView(withId(R.id.username)).perform(typeText("username"))

activityScenario.moveToState(Lifecycle.State.DESTROYED)
}
}
21 changes: 21 additions & 0 deletions app-test-suite/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
plugins {
id 'shoppingapp.android.lib'
id 'kotlin-android'
}

android {
namespace = "com.handstandsam.shoppingapp.android.tests.lib"

variantFilter { variant ->
setIgnore(!variant.name.toLowerCase().endsWith("debug"))
}
}

dependencies {
compileOnly project(path: ':app')

implementation libs.androidx.espresso
implementation libs.androidx.espresso.contrib
implementation libs.androidx.test.rules
implementation libs.androidx.testrunner
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.handstandsam.shoppingapp.tests

import androidx.lifecycle.Lifecycle
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.typeText
import androidx.test.espresso.matcher.ViewMatchers.withId
import com.handstandsam.shoppingapp.R
import com.handstandsam.shoppingapp.features.login.LoginActivity
import org.junit.Assert.assertTrue
import org.junit.Test

/**
* com.android.library
*/
class TestInLibraryModuleTest {

@Test
fun testInLibraryModule() {
println("Test in Library Module!")
assertTrue(true)
}
}
Loading
Loading