First working unit test

This commit is contained in:
Daniele 2021-09-05 19:31:00 +02:00
parent 359a78e237
commit 25848438b1
6 changed files with 57 additions and 42 deletions

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<targetSelectedWithDropDown>
<Target>
<type value="QUICK_BOOT_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="$USER_HOME$/.android/avd/Pixel_5_API_30.avd" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2021-09-05T17:23:36.351292Z" />
</component>
</project>

View File

@ -7,6 +7,7 @@
<entry key="app/src/main/res/layout/fragment_beer_detail.xml" value="0.536" /> <entry key="app/src/main/res/layout/fragment_beer_detail.xml" value="0.536" />
<entry key="app/src/main/res/layout/fragment_beers_list.xml" value="0.634963768115942" /> <entry key="app/src/main/res/layout/fragment_beers_list.xml" value="0.634963768115942" />
<entry key="app/src/main/res/layout/fragment_beers_listitem.xml" value="0.5307291666666667" /> <entry key="app/src/main/res/layout/fragment_beers_listitem.xml" value="0.5307291666666667" />
<entry key="app/src/main/res/menu/list_menu.xml" value="0.4759259259259259" />
</map> </map>
</option> </option>
</component> </component>

View File

@ -15,6 +15,7 @@ android {
versionName "1.0" versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
} }
buildTypes { buildTypes {
@ -36,7 +37,6 @@ android {
} }
dependencies { dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.6.0' implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1' implementation 'androidx.appcompat:appcompat:1.3.1'

View File

@ -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)
}
}

View File

@ -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<MainActivity>
= 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()))
}
}

View File

@ -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)
}
}