https://github.com/faruktoptas/mvvm-arch-sample
[WORK-IN-PROGRESS] Kotlin/Coroutines/Modular/Mvvm/LiveData/JUnit/Espresso
https://github.com/faruktoptas/mvvm-arch-sample
Last synced: about 1 month ago
JSON representation
[WORK-IN-PROGRESS] Kotlin/Coroutines/Modular/Mvvm/LiveData/JUnit/Espresso
- Host: GitHub
- URL: https://github.com/faruktoptas/mvvm-arch-sample
- Owner: faruktoptas
- License: apache-2.0
- Created: 2021-01-24T15:15:02.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-05-12T06:14:43.000Z (over 4 years ago)
- Last Synced: 2025-04-10T10:59:18.211Z (6 months ago)
- Language: Kotlin
- Homepage:
- Size: 189 KB
- Stars: 29
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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`
```kotlin
fun fetchItems() {
callService({ repo.getAlbums() }, {
albumsLive.postValue(it)
})
}
````MainRepositoryImpl.kt`
```kotlin
override suspend fun getAlbums() = apiWrapper { api.getAlbums() }}
```### Calling an api service with overrided error case
```kotlin
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](https://github.com/faruktoptas/mvvm-arch-sample/blob/master/network/src/test/java/me/toptas/architecture/network/ApiWrapperTest.kt)
* 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](https://medium.com/android-bits/espresso-robot-pattern-in-kotlin-fc820ce250f7)
* [x] Github actions