From 52d6c49ccc8399f3b9947ed30267659800ae5e5e Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sun, 3 Sep 2023 21:12:19 +0200 Subject: [PATCH] Ladybird: Add Espresso test on Android to verify we can load our views The simple smoke test makes sure that we can boot up an android emulator with our package in it, and that the WebView is visible on boot. More tests to come with more features :^) --- Ladybird/Android/build.gradle.kts | 1 + .../java/org/serenityos/ladybird/SmokeTest.kt | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 Ladybird/Android/src/androidTest/java/org/serenityos/ladybird/SmokeTest.kt diff --git a/Ladybird/Android/build.gradle.kts b/Ladybird/Android/build.gradle.kts index 19b2eb7c70..54ccb44044 100644 --- a/Ladybird/Android/build.gradle.kts +++ b/Ladybird/Android/build.gradle.kts @@ -75,5 +75,6 @@ dependencies { implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0") testImplementation("junit:junit:4.13.2") androidTestImplementation("androidx.test.ext:junit:1.1.5") + androidTestImplementation("androidx.test.ext:junit-ktx:1.1.5") androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") } diff --git a/Ladybird/Android/src/androidTest/java/org/serenityos/ladybird/SmokeTest.kt b/Ladybird/Android/src/androidTest/java/org/serenityos/ladybird/SmokeTest.kt new file mode 100644 index 0000000000..e9e7d1c384 --- /dev/null +++ b/Ladybird/Android/src/androidTest/java/org/serenityos/ladybird/SmokeTest.kt @@ -0,0 +1,40 @@ +package org.serenityos.ladybird + +import androidx.test.ext.junit.rules.activityScenarioRule +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed +import androidx.test.espresso.matcher.ViewMatchers.withId + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* +import org.junit.Rule + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class SmokeTest { + + @get:Rule + var activityScenarioRule = activityScenarioRule() + + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("org.serenityos.ladybird", appContext.packageName) + } + + @Test + fun loadWebView() { + // We can actually load a web view, and it is visible + onView(withId(R.id.web_view)).check(matches(isDisplayed())) + } +}