Issue#106 Update NavController example's sharedTest as well
This commit is contained in:
parent
9752d1643b
commit
d5ce57769f
10 changed files with 94 additions and 21 deletions
1
examplecase/example-navcontroller-shared-test/.gitignore
vendored
Normal file
1
examplecase/example-navcontroller-shared-test/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/build
|
||||
44
examplecase/example-navcontroller-shared-test/build.gradle
Normal file
44
examplecase/example-navcontroller-shared-test/build.gradle
Normal 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')
|
||||
}
|
||||
21
examplecase/example-navcontroller-shared-test/proguard-rules.pro
vendored
Normal file
21
examplecase/example-navcontroller-shared-test/proguard-rules.pro
vendored
Normal 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
|
||||
|
|
@ -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>
|
||||
|
|
@ -28,7 +28,7 @@ import org.junit.runner.RunWith
|
|||
* For more info check out https://developer.android.com/guide/navigation/navigation-testing
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class HomeNavigationTest {
|
||||
open class HomeNavigationSharedTest {
|
||||
|
||||
private lateinit var fragmentScenario: FragmentScenario<HomeFragment>
|
||||
private lateinit var testNavController: TestNavHostController
|
||||
|
|
@ -80,7 +80,8 @@ class HomeNavigationTest {
|
|||
.perform(ViewActions.click())
|
||||
|
||||
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 }
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +96,8 @@ class HomeNavigationTest {
|
|||
Espresso.onView(itemViewMatcher(position2)).perform(ViewActions.click())
|
||||
|
||||
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())
|
||||
Assert.assertEquals(position1, actualArgs.position)
|
||||
}
|
||||
|
|
@ -28,17 +28,6 @@ android {
|
|||
kotlinOptions {
|
||||
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
|
||||
packagingOptions {
|
||||
|
|
@ -56,12 +45,8 @@ dependencies {
|
|||
implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
|
||||
implementation "androidx.navigation:navigation-ui-ktx:$navigation_version"
|
||||
|
||||
debugImplementation "androidx.fragment:fragment-testing:1.5.3"
|
||||
|
||||
applyAppTestDependenciesTo(this)
|
||||
|
||||
testImplementation "androidx.navigation:navigation-testing:$navigation_version"
|
||||
testImplementation project(':test-util-android')
|
||||
androidTestImplementation project(':test-util-android')
|
||||
androidTestImplementation "androidx.navigation:navigation-testing:$navigation_version"
|
||||
debugImplementation "androidx.fragment:fragment-testing:1.5.3"
|
||||
testImplementation project(":examplecase:example-navcontroller-shared-test")
|
||||
androidTestImplementation project(":examplecase:example-navcontroller-shared-test")
|
||||
}
|
||||
|
|
@ -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()
|
||||
|
|
@ -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()
|
||||
|
|
@ -10,3 +10,4 @@ include ':test-util-android'
|
|||
include ':test-util-junit5-android'
|
||||
include ':app-shared-test'
|
||||
include ':examplecase:example-navcontroller'
|
||||
include ':examplecase:example-navcontroller-shared-test'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue