Skip to content

Commit 81ceae9

Browse files
authored
Add android instrumentation tests (#36)
1 parent 95b7e6b commit 81ceae9

File tree

14 files changed

+141
-7
lines changed

14 files changed

+141
-7
lines changed

.github/workflows/CI.yml

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ jobs:
1111
fail-fast: false
1212
matrix:
1313
os: [ macos-latest, ubuntu-latest, windows-latest ]
14-
job: [ test ]
1514

1615
runs-on: ${{ matrix.os }}
1716

@@ -50,17 +49,46 @@ jobs:
5049
java-version: 11
5150

5251
- name: Run macOS Tests
53-
if: matrix.os == 'macos-latest' && matrix.job == 'test'
52+
if: matrix.os == 'macos-latest'
5453
run: >
5554
./gradlew check --stacktrace
5655
-PKMP_TARGETS="JVM,JS,IOS_ARM32,IOS_ARM64,IOS_X64,IOS_SIMULATOR_ARM64,MACOS_ARM64,MACOS_X64,TVOS_ARM64,TVOS_X64,TVOS_SIMULATOR_ARM64,WATCHOS_ARM32,WATCHOS_ARM64,WATCHOS_DEVICE_ARM64,WATCHOS_X64,WATCHOS_X86,WATCHOS_SIMULATOR_ARM64,WASM,WASM_32"
5756
- name: Run Linux Tests
58-
if: matrix.os == 'ubuntu-latest' && matrix.job == 'test'
57+
if: matrix.os == 'ubuntu-latest'
5958
run: >
6059
./gradlew check --stacktrace
61-
-PKMP_TARGETS="JVM,JS,ANDROID,ANDROID_ARM32,ANDROID_ARM64,ANDROID_X64,ANDROID_X86,LINUX_ARM32HFP,LINUX_ARM64,LINUX_MIPS32,LINUX_MIPSEL32,LINUX_X64,WASM,WASM_32"
60+
-PKMP_TARGETS="JVM,JS,ANDROID_ARM32,ANDROID_ARM64,ANDROID_X64,ANDROID_X86,LINUX_ARM32HFP,LINUX_ARM64,LINUX_MIPS32,LINUX_MIPSEL32,LINUX_X64,WASM,WASM_32"
6261
- name: Run Windows Tests
63-
if: matrix.os == 'windows-latest' && matrix.job == 'test'
62+
if: matrix.os == 'windows-latest'
6463
run: >
6564
./gradlew check --stacktrace
6665
-PKMP_TARGETS="JVM,JS,MINGW_X64,MINGW_X86,WASM,WASM_32"
66+
67+
emulator:
68+
runs-on: macos-latest
69+
70+
strategy:
71+
fail-fast: false
72+
matrix:
73+
api-level: [ 15, 23, 29 ]
74+
steps:
75+
- name: Checkout Repo
76+
uses: actions/checkout@v3
77+
78+
- name: Validate Gradle Wrapper
79+
uses: gradle/wrapper-validation-action@v1
80+
81+
- name: Setup JDK
82+
uses: actions/[email protected]
83+
with:
84+
distribution: 'zulu'
85+
java-version: 19
86+
87+
- name: Build
88+
uses: gradle/gradle-build-action@v2
89+
90+
- name: Run Android Instrumented Tests
91+
uses: reactivecircus/android-emulator-runner@v2
92+
with:
93+
api-level: ${{ matrix.api-level }}
94+
script: ./gradlew :test-android:connectedCheck -PKMP_TARGETS="ANDROID,JVM"

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension
2020
@Suppress("DSL_SCOPE_VIOLATION")
2121
plugins {
2222
alias(libs.plugins.multiplatform) apply(false)
23+
alias(libs.plugins.android.library) apply(false)
2324
alias(libs.plugins.binaryCompat)
2425
alias(libs.plugins.gradleVersions)
2526
}

gradle.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
22
org.gradle.parallel=true
33
org.gradle.caching=true
44

5+
android.useAndroidX=true
6+
android.enableJetifier=true
7+
android.disableAutomaticComponentCreation=true
8+
59
kotlin.code.style=official
610
kotlin.js.compiler=both
11+
kotlin.mpp.androidSourceSetLayoutVersion=2
712
kotlin.mpp.enableCompatibilityMetadataVariant=true
813
kotlin.mpp.stability.nowarn=true
914
kotlin.native.binary.memoryModel=experimental

gradle/libs.versions.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
[versions]
2+
android = "7.4.2"
3+
androidxTestRunner = "1.5.2"
24
binaryCompat = "0.13.2"
35
bouncyCastle = "1.73"
46
configuration = "0.1.0"
5-
cryptoCore = "0.2.6"
6-
cryptoHash = "0.2.6"
7+
cryptoCore = "0.2.7"
8+
cryptoHash = "0.2.7"
79
encoding = "1.2.2"
810
gradleVersions = "0.46.0"
911
kotlin = "1.8.21"
@@ -22,11 +24,13 @@ gradle-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.
2224
gradle-maven-publish = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "publish" }
2325

2426
# Tests
27+
androidx-test-runner = { module = "androidx.test:runner", version.ref = "androidxTestRunner" }
2528
bouncyCastle = { module = "org.bouncycastle:bcprov-ext-jdk15to18", version.ref = "bouncyCastle" }
2629
encoding-base16 = { module = "io.matthewnelson.kotlin-components:encoding-base16", version.ref = "encoding" }
2730
encoding-base64 = { module = "io.matthewnelson.kotlin-components:encoding-base64", version.ref = "encoding" }
2831

2932
[plugins]
33+
android-library = { id = "com.android.library", version.ref = "android" }
3034
binaryCompat = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "binaryCompat" }
3135
gradleVersions = { id = "com.github.ben-manes.versions", version.ref = "gradleVersions" }
3236
multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }

settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pluginManagement {
44
repositories {
55
mavenCentral()
66
gradlePluginPortal()
7+
google()
78
}
89
}
910

@@ -31,4 +32,5 @@ if (CHECK_PUBLICATION != null) {
3132

3233
include(":bom")
3334
include(":tools:testing")
35+
include(":test-android")
3436
}

test-android/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

test-android/api/test-android.api

Whitespace-only changes.

test-android/build.gradle.kts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2023 Toxicity
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
**/
16+
plugins {
17+
id("configuration")
18+
}
19+
20+
repositories {
21+
google()
22+
}
23+
24+
kmpConfiguration {
25+
this.configure {
26+
androidLibrary {
27+
kotlinJvmTarget = JavaVersion.VERSION_11
28+
compileSourceCompatibility = JavaVersion.VERSION_11
29+
compileTargetCompatibility = JavaVersion.VERSION_11
30+
31+
android {
32+
namespace = "org.kotlincrypto.macs"
33+
compileSdk = 33
34+
35+
defaultConfig {
36+
minSdk = 14
37+
38+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
39+
}
40+
41+
libraryVariants.all {
42+
generateBuildConfigProvider.configure {
43+
enabled = false
44+
}
45+
}
46+
}
47+
48+
sourceSetTestInstrumented {
49+
kotlin.srcDir("src/androidInstrumentedTest/hmac-md5")
50+
kotlin.srcDir("src/androidInstrumentedTest/hmac-sha1")
51+
kotlin.srcDir("src/androidInstrumentedTest/hmac-sha2")
52+
kotlin.srcDir("src/androidInstrumentedTest/hmac-sha3")
53+
kotlin.srcDir("src/androidInstrumentedTest/kmac")
54+
55+
dependencies {
56+
implementation(libs.androidx.test.runner)
57+
implementation(libs.encoding.base16)
58+
implementation(kotlin("test"))
59+
60+
implementation(project(":library:hmac:hmac-md5"))
61+
implementation(project(":library:hmac:hmac-sha1"))
62+
implementation(project(":library:hmac:hmac-sha2"))
63+
implementation(project(":library:hmac:hmac-sha3"))
64+
implementation(project(":library:kmac"))
65+
implementation(project(":tools:testing"))
66+
}
67+
}
68+
}
69+
}
70+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../library/hmac/hmac-md5/src/commonTest/kotlin
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../library/hmac/hmac-sha1/src/commonTest/kotlin

0 commit comments

Comments
 (0)