Swent-team-6 / icebreakrr

2 stars 1 forks source link

Feature/end to end #141

Closed SamSteu closed 4 days ago

SamSteu commented 6 days ago

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 :

  1. 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.
  2. main/java/com/github/se/icebreakrr/IcebreakrrApplication.kt
    • Created this file, which extends the Application class and includes the @HiltAndroidApp annotation.
    • This serves as the application's entry point for Hilt and ensures dependency injection happens before the onCreate method in MainActivity.
  3. androidTest/java/com/github/se/CustomTestRunner.kt
    • Added this file as the entry point for Hilt during testing. It ensures the test environment uses dependency injection.
  4. AndroidManifest.xml
    • Modified to include android:name="com.github.se.icebreakrr.IcebreakrrApplication", directing Hilt to the application's entry point.
  5. main/java/com/github/se/icebreakrr/di/module/AppModule.kt
    • Created this module to define the real instances of objects used in the application.
    • Annotated with @Module and @InstallIn(SingletonComponent::class), it provides singleton instances for dependency injection throughout the app.
  6. androidTest/java/com/github/se/di/module/TestModule.kt
    • 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.
  7. M1_Test and M2_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().
  8. 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.

sonarcloud[bot] commented 4 days ago

Quality Gate Passed Quality Gate passed

Issues
10 New issues
0 Accepted issues

Measures
0 Security Hotspots
71.7% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud