Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce koin, add mockk for unit tests #180

Merged

Conversation

carstenhag
Copy link
Collaborator

@carstenhag carstenhag commented Nov 9, 2024

  • Introduce koin. For that, App.kt was added, which is a singleton class that subclasses Android's Application. In there, koin gets set up.
  • Interfaces were added to classes that we want to be able to replace (usually for testing, but there's also a compose case at ExportImportDialog).
  • If you want to use a class (or context) inside another class, define its constructor like this. Koin will then automatically pick a IPeriodDatabaseHelper etc:
class CalculationsHelper(
    private val dbHelper: IPeriodDatabaseHelper,
) : ICalculationsHelper {
  • All of this means, that you should not create new instances of classes/interfaces like PeriodDatabaseHelper(). Class instantiation is only done by the DI framework, so here koin.
  • Inside composables, we are for now using koinInject() to be able to use calculation/db classes. But this still breaks previews, as in there, koin is not actually in use. It compiles, but that's it 😛

In the future, we will have ViewModels. Those will then access IPeriodDatabaseHelper, IPeriodPrediction, etc.

Fixes #179, prerequisite for #97

@@ -1,11 +0,0 @@
package com.mensinator.app
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EmmaTellblom I removed this, felt like it was not really needed :)

@carstenhag carstenhag marked this pull request as ready for review November 9, 2024 21:14
@EmmaTellblom EmmaTellblom merged commit eabcfe8 into EmmaTellblom:main Nov 11, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Intoduce a Dependency Injection framework, create interfaces for service/repository classes
2 participants