Issue#106 Update NavController example's sharedTest as well

This commit is contained in:
Gergely Hegedus 2022-09-26 17:38:28 +03:00
parent 9752d1643b
commit d5ce57769f
10 changed files with 94 additions and 21 deletions

View file

@ -0,0 +1 @@
/build

View file

@ -0,0 +1,44 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'androidx.navigation.safeargs.kotlin'
}
android {
compileSdk 31
defaultConfig {
minSdk 21
targetSdk 31
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
lintOptions {
ignore 'FragmentGradleConfiguration'
}
}
dependencies {
applyAppSharedTestDependenciesTo(this)
implementation project(":examplecase:example-navcontroller")
//noinspection FragmentGradleConfiguration
implementation "androidx.fragment:fragment-testing:1.5.3"
implementation "androidx.navigation:navigation-testing:$navigation_version"
implementation project(':test-util-android')
}

View file

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.fnives.test.showcase.examplecase.navcontroller.shared.test">
</manifest>

View file

@ -28,7 +28,7 @@ import org.junit.runner.RunWith
* For more info check out https://developer.android.com/guide/navigation/navigation-testing * For more info check out https://developer.android.com/guide/navigation/navigation-testing
*/ */
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
class HomeNavigationTest { open class HomeNavigationSharedTest {
private lateinit var fragmentScenario: FragmentScenario<HomeFragment> private lateinit var fragmentScenario: FragmentScenario<HomeFragment>
private lateinit var testNavController: TestNavHostController private lateinit var testNavController: TestNavHostController
@ -80,7 +80,8 @@ class HomeNavigationTest {
.perform(ViewActions.click()) .perform(ViewActions.click())
Assert.assertEquals(R.id.detailFragment, testNavController.currentDestination?.id) Assert.assertEquals(R.id.detailFragment, testNavController.currentDestination?.id)
Assert.assertEquals(listOf(R.id.nav_example_xml, R.id.homeFragment, R.id.detailFragment), testNavController.backStack.map { it.destination.id }) val expectedBackstack = listOf(R.id.nav_example_xml, R.id.homeFragment, R.id.detailFragment)
Assert.assertEquals(expectedBackstack, testNavController.backStack.map { it.destination.id })
testNavController.backStack.map { it.arguments } testNavController.backStack.map { it.arguments }
} }
@ -95,7 +96,8 @@ class HomeNavigationTest {
Espresso.onView(itemViewMatcher(position2)).perform(ViewActions.click()) Espresso.onView(itemViewMatcher(position2)).perform(ViewActions.click())
Assert.assertEquals(R.id.detailFragment, testNavController.currentDestination?.id) Assert.assertEquals(R.id.detailFragment, testNavController.currentDestination?.id)
Assert.assertEquals(listOf(R.id.nav_example_xml, R.id.homeFragment, R.id.detailFragment), testNavController.backStack.map { it.destination.id }) val expectedBackstack = listOf(R.id.nav_example_xml, R.id.homeFragment, R.id.detailFragment)
Assert.assertEquals(expectedBackstack, testNavController.backStack.map { it.destination.id })
val actualArgs = DetailFragmentArgs.fromBundle(testNavController.backStack.last().arguments ?: Bundle()) val actualArgs = DetailFragmentArgs.fromBundle(testNavController.backStack.last().arguments ?: Bundle())
Assert.assertEquals(position1, actualArgs.position) Assert.assertEquals(position1, actualArgs.position)
} }

View file

@ -28,17 +28,6 @@ android {
kotlinOptions { kotlinOptions {
jvmTarget = '1.8' jvmTarget = '1.8'
} }
sourceSets {
androidTest {
java.srcDirs += "src/sharedTest/java"
assets.srcDirs += files("$projectDir/schemas".toString())
}
test {
java.srcDirs += "src/sharedTest/java"
java.srcDirs += "src/robolectricTest/java"
resources.srcDirs += files("$projectDir/schemas".toString())
}
}
// needed for androidTest // needed for androidTest
packagingOptions { packagingOptions {
@ -56,12 +45,8 @@ dependencies {
implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version" implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
implementation "androidx.navigation:navigation-ui-ktx:$navigation_version" implementation "androidx.navigation:navigation-ui-ktx:$navigation_version"
debugImplementation "androidx.fragment:fragment-testing:1.5.3"
applyAppTestDependenciesTo(this) applyAppTestDependenciesTo(this)
debugImplementation "androidx.fragment:fragment-testing:1.5.3"
testImplementation "androidx.navigation:navigation-testing:$navigation_version" testImplementation project(":examplecase:example-navcontroller-shared-test")
testImplementation project(':test-util-android') androidTestImplementation project(":examplecase:example-navcontroller-shared-test")
androidTestImplementation project(':test-util-android')
androidTestImplementation "androidx.navigation:navigation-testing:$navigation_version"
} }

View file

@ -0,0 +1,7 @@
package org.fnives.test.showcase.examplecase.navcontroller
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class HomeNavigationTest : HomeNavigationSharedTest()

View file

@ -0,0 +1,7 @@
package org.fnives.test.showcase.examplecase.navcontroller
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class HomeNavigationTest : HomeNavigationSharedTest()

View file

@ -10,3 +10,4 @@ include ':test-util-android'
include ':test-util-junit5-android' include ':test-util-junit5-android'
include ':app-shared-test' include ':app-shared-test'
include ':examplecase:example-navcontroller' include ':examplecase:example-navcontroller'
include ':examplecase:example-navcontroller-shared-test'