A sample project demonstrating unit testing in an MVVM architecture using Room Database, Retrofit, and Repository pattern in Android.
This project demonstrates how to write unit tests for an MVVM-based Android application using Room Database, Retrofit API service, and Repository pattern. The tests cover:
- ViewModel tests
- Repository tests
- Retrofit API service tests
- Room Database tests
- Room Database tests
- Kotlin Flows & Coroutines tests
- Turbine for testing Flows
The unit tests validate different layers of the MVVM architecture:
-
ViewModel Tests Ensuring correct ViewModel behavior.
-
Repository Tests Mocking data sources and testing repository logic.
-
Retrofit API Tests Mocking API responses.
-
Room Database Tests Testing local database operations.
-
Kotlin Flow & Coroutine Tests Validating asynchronous data streams.
-
Turbine for Flow Testing Ensuring proper emission and collection behavior.
- Kotlin
- MVVM Architecture
- Hilt for Dependency Injection
- Retrofit for API calls
- Room for local database
- JUnit & Mockito for Unit Testing
- Kotlin Coroutines & Flow
- Turbine for Flow Testing
- Clone the repository:
git clone https://github.com/bilal96aslam/MVVMTestSuite.git
- Open in Android Studio.
- Build and run the project.
Contributions are welcome! Feel free to submit issues or pull requests.