Skip to content

[WORK-IN-PROGRESS] Kotlin/Coroutines/Modular/Mvvm/LiveData/JUnit/Espresso

License

Notifications You must be signed in to change notification settings

faruktoptas/mvvm-arch-sample

Repository files navigation

mvvm-arch-sample Android CI Action

[WORK-IN-PROGRESS]

  • Less boilerplate code
  • Easy to read
  • Testable (Unit and Instrumantation)
  • Modularized by layer (Feature modules coming soon)

Architecture

Screen Shot 2021-01-25 at 22 47 37

Screen Shot 2021-01-25 at 22 52 58

What is used?

  • JetPack ViewModel/LiveData
  • Coroutines
  • Koin
  • DataBinding
  • Unit Tests
  • Instrumentation Tests
  • Jacoco test coverage

Samples

Calling an api service (Errors are handled in base classes)

MainViewModel.kt

fun fetchItems() {
    callService({ repo.getAlbums() }, {
        albumsLive.postValue(it)
    })
}

MainRepositoryImpl.kt

override suspend fun getAlbums() = apiWrapper { api.getAlbums() }}

Calling an api service with overrided error case

fun fetchItems() {
    callService({ repo.getAlbums() },
        success = {
            albumsLive.postValue(it)
        },
        failure = {
            if (it is AError.Authorization) {
                // clear token
            } else {
                postError(it)
            }
        }
    )
}

Testing

  • All business logic is kept in ViewModels. Trying to keep ViewModel coverages near 100%.
  • All network cases also tested with ApiWrapperTest

Screen Shot 2021-01-25 at 23 04 05

Screen Shot 2021-01-25 at 23 04 33

  • Ui bound cases and view classes are tested with Espresso.

Todos

  • At least 2 screens with more interaction
  • Navigation
  • Feature modules
  • Easy and readeble Espresso tests with Robot pattern
  • Github actions

About

[WORK-IN-PROGRESS] Kotlin/Coroutines/Modular/Mvvm/LiveData/JUnit/Espresso

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages