From 25848438b111aba8738341a2d0fd83f5df7178c5 Mon Sep 17 00:00:00 2001 From: Daniele Date: Sun, 5 Sep 2021 19:31:00 +0200 Subject: [PATCH] First working unit test --- .idea/deploymentTargetDropDown.xml | 17 +++++++++ .idea/misc.xml | 1 + app/build.gradle | 2 +- .../subitobeers/ExampleInstrumentedTest.kt | 24 ------------ .../subitobeers/ui/BeersFragmentTest.kt | 38 +++++++++++++++++++ .../subitobeers/ExampleUnitTest.kt | 17 --------- 6 files changed, 57 insertions(+), 42 deletions(-) create mode 100644 .idea/deploymentTargetDropDown.xml delete mode 100644 app/src/androidTest/java/it/danieleverducci/subitobeers/ExampleInstrumentedTest.kt create mode 100644 app/src/androidTest/java/it/danieleverducci/subitobeers/ui/BeersFragmentTest.kt delete mode 100644 app/src/test/java/it/danieleverducci/subitobeers/ExampleUnitTest.kt diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000..8d35f32 --- /dev/null +++ b/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 9442b32..16cec7e 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -7,6 +7,7 @@ + diff --git a/app/build.gradle b/app/build.gradle index a77e89c..c637a3c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -15,6 +15,7 @@ android { versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" +// testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner" } buildTypes { @@ -36,7 +37,6 @@ android { } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation 'androidx.core:core-ktx:1.6.0' implementation 'androidx.appcompat:appcompat:1.3.1' diff --git a/app/src/androidTest/java/it/danieleverducci/subitobeers/ExampleInstrumentedTest.kt b/app/src/androidTest/java/it/danieleverducci/subitobeers/ExampleInstrumentedTest.kt deleted file mode 100644 index 2135e0b..0000000 --- a/app/src/androidTest/java/it/danieleverducci/subitobeers/ExampleInstrumentedTest.kt +++ /dev/null @@ -1,24 +0,0 @@ -package it.danieleverducci.subitobeers - -import androidx.test.platform.app.InstrumentationRegistry -import androidx.test.ext.junit.runners.AndroidJUnit4 - -import org.junit.Test -import org.junit.runner.RunWith - -import org.junit.Assert.* - -/** - * Instrumented test, which will execute on an Android device. - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -@RunWith(AndroidJUnit4::class) -class ExampleInstrumentedTest { - @Test - fun useAppContext() { - // Context of the app under test. - val appContext = InstrumentationRegistry.getInstrumentation().targetContext - assertEquals("it.danieleverducci.subitobeers", appContext.packageName) - } -} \ No newline at end of file diff --git a/app/src/androidTest/java/it/danieleverducci/subitobeers/ui/BeersFragmentTest.kt b/app/src/androidTest/java/it/danieleverducci/subitobeers/ui/BeersFragmentTest.kt new file mode 100644 index 0000000..a2e9e80 --- /dev/null +++ b/app/src/androidTest/java/it/danieleverducci/subitobeers/ui/BeersFragmentTest.kt @@ -0,0 +1,38 @@ +package it.danieleverducci.subitobeers.ui + +import androidx.test.espresso.Espresso +import androidx.test.espresso.action.ViewActions +import androidx.test.espresso.assertion.ViewAssertions +import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.ext.junit.rules.ActivityScenarioRule +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.LargeTest +import it.danieleverducci.subitobeers.MainActivity +import it.danieleverducci.subitobeers.R +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +@LargeTest +class BeersFragmentTest { + + @get:Rule + var activityRule: ActivityScenarioRule + = ActivityScenarioRule(MainActivity::class.java) + + @Test + fun filter_BeersFragmentTest() { + // Filters for the current date as brewed start date (we expect 0 results) + // Click menu item + Espresso.onView(ViewMatchers.withId(R.id.action_filter)).perform(ViewActions.click()) + // Click filter button + Espresso.onView(ViewMatchers.withId(R.id.list_filter_since_bt)).perform(ViewActions.click()) + // Click ok on datepicker + Espresso.onView(ViewMatchers.withText("OK")).perform(ViewActions.click()) + Thread.sleep(500) + // Check the list empty message is correctly displayed + Espresso.onView(ViewMatchers.withId(R.id.list_empty)) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + } +} \ No newline at end of file diff --git a/app/src/test/java/it/danieleverducci/subitobeers/ExampleUnitTest.kt b/app/src/test/java/it/danieleverducci/subitobeers/ExampleUnitTest.kt deleted file mode 100644 index 92ee02c..0000000 --- a/app/src/test/java/it/danieleverducci/subitobeers/ExampleUnitTest.kt +++ /dev/null @@ -1,17 +0,0 @@ -package it.danieleverducci.subitobeers - -import org.junit.Test - -import org.junit.Assert.* - -/** - * Example local unit test, which will execute on the development machine (host). - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -class ExampleUnitTest { - @Test - fun addition_isCorrect() { - assertEquals(4, 2 + 2) - } -} \ No newline at end of file