Skip to content
Permalink
Browse files

Implement android test (#1141)

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
Kerooker committed Jan 4, 2020
1 parent b9f34bf commit 0d556b6e9b658b7fb874ee9e33ad3a573d3db90c
@@ -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"
@@ -23,8 +23,14 @@ buildscript {

dependencies {
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokkaVersion"
classpath 'com.android.tools.build:gradle:3.5.0'
// classpath "io.kotest:kotest-gradle-plugin:1.1.1-LOCAL"
}

repositories {
mavenCentral()
google()
}
}

plugins {
@@ -43,6 +49,7 @@ allprojects {
repositories {
mavenCentral()
jcenter()
google()
}

sourceCompatibility = 1.8
@@ -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")
}
@@ -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!"
}
}
}
}
@@ -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>
@@ -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)
}
}
@@ -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>
@@ -0,0 +1 @@
<resources></resources>
@@ -22,3 +22,4 @@ include("kotest-tests:kotest-tests-timeout")
//include("kotest-tests:kotest-tests-junit4-assertions")
include("kotest-tests:kotest-tests-junit5")
include("kotest-tests:kotest-tests-parallelism")
include("kotest-tests-android")

0 comments on commit 0d556b6

Please sign in to comment.
You can’t perform that action at this time.