Skip to content

Writing a Fragment Test

Marcel Schnelle edited this page Jul 31, 2021 · 2 revisions

Testing a Fragment with JUnit 5 works exactly like it does with JUnit 4: through the FragmentScenario API. Unlike Activity tests, there is no special extension for Fragment-based tests: If you want to launch a scenario for a Fragment, simply use the API directly:

class MyFragmentTest {
    @Test
    fun myTest() {
        val scenario = FragmentScenario.launch<MyFragment>()
        // Do something with the scenario here...
    }
}