mvvm-arch-sample
mvvm-arch-sample copied to clipboard
[WORK-IN-PROGRESS] Kotlin/Coroutines/Modular/Mvvm/LiveData/JUnit/Espresso
mvvm-arch-sample 
[WORK-IN-PROGRESS]
- Less boilerplate code
- Easy to read
- Testable (Unit and Instrumantation)
- Modularized by layer (Feature modules coming soon)
Architecture


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


- 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
- [x] Github actions