我开始使用hilt
,在测试时遇到了问题。
这是生成以下错误的代码:
@HiltAndroidTest
@RunWith(CommonUiRunner::class)
class PhoneEditTextTest {
@Test
fun testThatNumberFormatted() {
val controller = Robolectric.buildActivity(AppCompatActivity::class.java)
val activity = controller.get()
val editText = PhoneEditText(activity)
activity.setContentView(editText)
controller.setup()
}
}
@Module
@InstallIn(ApplicationComponent::class)
object ApplicationModule {
@Provides
@Singleton
fun providePhoneNumberUtil(app: Application): PhoneNumberUtil = PhoneNumberUtil.createInstance(AssetsMetadataLoader(app.assets))
}
@Module
@InstallIn(ApplicationComponent::class)
object CountriesFeatureModule {
@Provides
@Singleton
fun providesApi(app: Application): CountriesFeatureApi = CountriesFeatureImpl(app.assets)
}
返回:
APPLICATION and COUNTRIES-FEATURE modules contains in INJECTOR gradle-module.
你知道如何解决这个问题吗?