This pull request implements the end-to-end test for M2 and resolves issues in the end-to-end test for M1. To achieve this, I set up Hilt to handle the dependency injection of Firebase objects. Below is a breakdown of the changes made:
Files Modified or Created for Hilt Integration :
app/build.gradle.kts
Added dependencies for kapt (needed to process certain Hilt annotations), dagger, and Hilt.
Since Hilt is built on top of Dagger, these additions simplify dependency injection.
Created this module to define mocked implementations of objects for testing.
Annotated with @Module and @TestInstallIn(components = [SingletonComponent::class], replaces = [FirebaseAuthModule::class]), it replaces real instances from AppModule with mocks
during tests.
M1_TestandM2_Test
Updated these test classes to use Hilt for dependency injection:
Annotated the class with @HiltAndroidTest to enable dependency injection in tests.
Annotated fields to be injected using @Inject lateinit var authInjected: FirebaseAuth.
Added a Hilt rule with @get:Rule var hiltRule = HiltAndroidRule(this).
Injected mocked objects using hiltRule.inject().
MainActivity
Annotated with @AndroidEntryPoint to indicate that Hilt should handle dependency injection
for this activity.
Used @Inject lateinit var auth: FirebaseAuth to specify the objects to be injected.
Depending on whether the app is running or being tested, Hilt injects real Firebase instances or
mocked ones.
Summary of Hilt Behavior
When Running the App:
Hilt detects fields in MainActivity annotated with @Inject and performs dependency
injection via IcebreakrrApplication.
It uses the real instances of objects defined in AppModule.
When Running Tests:
Hilt initializes via CustomTestRunner and injects dependencies into MainActivity using
mocked implementations from TestModule.
Once all that was set up, I needed to add in parameters of all composable and/or repository and/or view models of the injected FirebaseAuth and FirebaseFirestore. This implies that a lot of tests needed to be changed to fit these new parameters, So a lot of files needed to be modified to fit the new architecture.
This pull request implements the end-to-end test for M2 and resolves issues in the end-to-end test for M1. To achieve this, I set up
Hilt
to handle the dependency injection of Firebase objects. Below is a breakdown of the changes made:Files Modified or Created for Hilt Integration :
app/build.gradle.kts
kapt
(needed to process certainHilt
annotations),dagger
, andHilt
.Hilt
is built on top ofDagger
, these additions simplify dependency injection.main/java/com/github/se/icebreakrr/IcebreakrrApplication.kt
Application
class and includes the@HiltAndroidApp
annotation.Hilt
and ensures dependency injection happens before theonCreate
method inMainActivity
.androidTest/java/com/github/se/CustomTestRunner.kt
Hilt
during testing. It ensures the test environment uses dependency injection.AndroidManifest.xml
android:name="com.github.se.icebreakrr.IcebreakrrApplication"
, directingHilt
to the application's entry point.main/java/com/github/se/icebreakrr/di/module/AppModule.kt
@Module
and@InstallIn(SingletonComponent::class)
, it provides singleton instances for dependency injection throughout the app.androidTest/java/com/github/se/di/module/TestModule.kt
@Module
and@TestInstallIn(components = [SingletonComponent::class], replaces = [FirebaseAuthModule::class])
, it replaces real instances fromAppModule
with mocks during tests.M1_Test
andM2_Test
Hilt
for dependency injection:@HiltAndroidTest
to enable dependency injection in tests.@Inject lateinit var authInjected: FirebaseAuth
.@get:Rule var hiltRule = HiltAndroidRule(this)
.hiltRule.inject()
.MainActivity
@AndroidEntryPoint
to indicate thatHilt
should handle dependency injection for this activity.@Inject lateinit var auth: FirebaseAuth
to specify the objects to be injected.Hilt
injects real Firebase instances or mocked ones. Summary of Hilt BehaviorHilt
detects fields inMainActivity
annotated with@Inject
and performs dependency injection viaIcebreakrrApplication
.AppModule
.Hilt
initializes viaCustomTestRunner
and injects dependencies intoMainActivity
using mocked implementations fromTestModule
.Once all that was set up, I needed to add in parameters of all composable and/or repository and/or view models of the injected
FirebaseAuth
andFirebaseFirestore
. This implies that a lot of tests needed to be changed to fit these new parameters, So a lot of files needed to be modified to fit the new architecture.