2

Fragment is not loading in Unit Test.

Code:

@RunWith(AndroidJUnit4::class)
class DataFeature  {

    @Test
    fun testEventFragment() {
            val fragmentArgs = bundleOf("test" to "100")
            val scenario = launchFragmentInContainer<DetailFragment>(fragmentArgs)
    }
}

Error:

java.lang.IllegalStateException: Hilt Fragments must be attached to an @AndroidEntryPoint Activity. Found: class androidx.fragment.app.testing.FragmentScenario$EmptyFragmentActivity

Fragment file

@AndroidEntryPoint
class DetailFragment : Fragment() {....}

while I am using Hilt in my application code. It's showing error in test case. It's not launching that fragment. I am using jetpack navigation controller as well.

Any help would be appreciated! Thanks in Advance.

Bhoomika Brahmbhatt
  • 7,404
  • 3
  • 29
  • 44

1 Answers1

0

try to downgrade your classpath to

classpath 'com.google.dagger:hilt-android-gradle-plugin:2.38.1'
3ameration
  • 101
  • 2
  • 3