-
Notifications
You must be signed in to change notification settings - Fork 643
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Executes AndroidTest through a Github action that runs an emulator and runs all android tests. This commit only implements a very basic hello world test, but we can escalate it from here.
- Loading branch information
Showing
9 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: "Android Test" | ||
|
||
on: | ||
push: | ||
|
||
jobs: | ||
test: | ||
runs-on: macOS-latest | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: run tests | ||
uses: reactivecircus/android-emulator-runner@v2 | ||
with: | ||
api-level: 28 | ||
script: "./gradlew kotest-tests-android:connectedCheck kotest-tests-android:testDebugUnitTest" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import org.jetbrains.kotlin.config.KotlinCompilerVersion | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions | ||
|
||
plugins { | ||
id("com.android.application") | ||
kotlin("android") | ||
kotlin("android.extensions") | ||
kotlin("kapt") | ||
} | ||
|
||
android { | ||
compileSdkVersion(28) | ||
|
||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
lintOptions { | ||
tasks.lint.get().enabled = false | ||
} | ||
|
||
kotlinOptions { | ||
val opts = this as KotlinJvmOptions | ||
opts.jvmTarget = "1.8" | ||
} | ||
|
||
defaultConfig { | ||
applicationId = "io.kotlintest.androidtests" | ||
minSdkVersion(21) | ||
targetSdkVersion(28) | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
testOptions { | ||
unitTests.isIncludeAndroidResources = true | ||
unitTests.all(closureOf<Test> { | ||
useJUnitPlatform() | ||
testLogging.showStackTraces = true | ||
} as groovy.lang.Closure<Test>) | ||
} | ||
|
||
packagingOptions { | ||
exclude("META-INF/LICENSE.md") | ||
exclude("META-INF/LICENSE-notice.md") | ||
} | ||
} | ||
|
||
dependencies { | ||
// Kotlin | ||
implementation(kotlin("stdlib-jdk8", KotlinCompilerVersion.VERSION)) | ||
implementation("org.jetbrains.kotlin:kotlin-reflect:1.3.61") | ||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.14.0") | ||
|
||
// Android | ||
implementation("androidx.core:core-ktx:1.2.0-rc01") | ||
|
||
// AndroidTest | ||
androidTestImplementation("androidx.test.espresso:espresso-core:3.2.0") | ||
androidTestImplementation("io.kotlintest:kotlintest-runner-junit4:3.4.2") { exclude(module = "objenesis") } | ||
androidTestImplementation("androidx.test:core:1.2.0") | ||
androidTestImplementation("androidx.test:core-ktx:1.2.0") | ||
} |
19 changes: 19 additions & 0 deletions
19
kotest-tests-android/src/androidTest/java/io/kotest/androidtest/MainActivityTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.kotest.androidtest | ||
|
||
import androidx.test.core.app.launchActivity | ||
import io.kotlintest.shouldBe | ||
import io.kotlintest.specs.StringSpec | ||
import kotlinx.android.synthetic.main.activity_main.textview | ||
|
||
class MainActivityTest : StringSpec() { | ||
|
||
init { | ||
"Hello World test" { | ||
val scenario = launchActivity<MainActivity>() | ||
|
||
scenario.onActivity { | ||
it.textview.text shouldBe "Kotest!" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="io.kotest.androidtest"> | ||
|
||
<application> | ||
<activity android:name="io.kotest.androidtest.MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
</manifest> |
12 changes: 12 additions & 0 deletions
12
kotest-tests-android/src/main/java/io/kotest/androidtest/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.kotest.androidtest | ||
|
||
import android.app.Activity | ||
import android.os.Bundle | ||
|
||
class MainActivity : Activity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
kotest-tests-android/src/main/res/layout/activity_main.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context="io.kotest.androidtest.MainActivity"> | ||
|
||
<TextView | ||
android:id="@+id/textview" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:text="Kotest!"/> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<resources></resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters