sergio-sastre / AndroidUiTestingUtils

A set of TestRules, ActivityScenarios and utils to facilitate UI and screenshot testing under given configurations: FontSizes, Locales...
MIT License
293 stars 14 forks source link

Android-Testify: Facilitate screenshot tests for Fragments #100

Closed sergio-sastre closed 8 months ago

sergio-sastre commented 8 months ago

Describe the bug It is a little bit cumbersome to write Android-Testify Screenshot tests for Fragments:

@UnhappyPath
    @FragmentTest
    @Test
    fun snapFragment() {
        activityScreenshotRule
            .setViewModifications {
                activityScreenshotRule.activity.supportFragmentManager.beginTransaction()
                    .add(
                        android.R.id.content,
                        CoffeeDrinksFragment().apply { this.arguments = bundleOf("coffee_shop_name" to "MyCoffeeShop") },
                        "Fragment"
                    )
                    .commitNow()
            }
            .setScreenshotViewProvider {
                activityScreenshotRule.activity.supportFragmentManager
                    .findFragmentByTag("Fragment")!!.requireView()
            }
            .assertSame(
                name = "CoffeeDrinksComposeFragment_UnhappyPath",
            )
    }

Ideally we can simplify it.

Expected behavior Something like this:

@UnhappyPath
    @FragmentTest
    @Test
    fun snapFragment() {
        activityScreenshotRule
            .setScreenshotFragment(
               fragment = CoffeeDrinksFragment(),
               fragmentArgs = bundleOf("coffee_shop_name" to "MyCoffeeShop")
            )
            .assertSame(
                name = "CoffeeDrinksComposeFragment_UnhappyPath",
            )
    }

add this in the :android-testify module

sergio-sastre commented 8 months ago

Added in 2.2.0