This repository contains sample code for testing an Android application using the MVVM architecture with ViewModel, LiveData, and Repository patterns. The focus is on unit testing and UI testing in the To-Do app.
-
Name: Phan Dinh Trung.
-
StudentID: 22110083.
- This project is part of Google's Advanced Android Testing course, demonstrating best practices for writing tests in Android applications. The code includes unit tests, instrumentation tests, and UI tests using JUnit, Mockito, and Espresso.
The TasksViewModelTest.kt file contains unit tests for the TasksViewModel class, ensuring that the ViewModel functions correctly under various scenarios.
-
Utilizes JUnit and Mockito for unit testing.
-
Tests ViewModel logic without requiring a real UI or database.
-
Verifies LiveData updates correctly.
-
Mocks repository dependencies to isolate ViewModel behavior.
-
Checking whether the ViewModel loads tasks correctly.
-
Filtering active and completed tasks.
-
Validating empty states and error handling.
Kotlin as the programming language.
-
Android ViewModel for UI-related data management.
-
LiveData for observable data streams.
-
JUnit for unit testing.
-
Mockito for dependency mocking.
-
Espresso for UI testing.
To execute the tests:
-
Open the project in Android Studio.
-
Ensure that the project is built using JDK version 11 by navigating to File → Settings → Build, Execution, Deployment → Build Tools → Gradle and selecting JDK 11.
-
Navigate to TasksViewModelTest.kt or StatisticsUtilsTest.kt.
-
Select the test function you want to run and execute it.