This repository demonstrates best practices for testing Android applications using modern tools and frameworks. The project focuses on unit testing, coroutine handling, flow testing, and more, all built with Kotlin.
Android Testing is a project designed to showcase how to write effective and reliable unit tests for Android applications. This project utilizes Test-Driven Development (TDD) principles, ensuring the development of robust, maintainable, and bug-free code.
- Unit testing with JUnit
- Coroutine testing with Kotlin Coroutines Test
- Flow testing to verify asynchronous data streams
- Usage of mock frameworks for test doubles
- Code coverage analysis using modern tools
- Kotlin: Primary programming language
- JUnit: Framework for writing and running unit tests
- Mockk: Library for creating mocks and stubs
- Kotlin Coroutines: Asynchronous programming
- Flows: Reactive streams in Kotlin
- Kotlin Coroutines Test: Framework for coroutine testing
Ensure you have the following installed:
- Android Studio (latest version recommended)
- Kotlin (1.5 or above)
- Gradle (configured in Android Studio)
-
Clone the repository:
git clone https://github.com/yourusername/android-testing.git
-
Open the project in Android Studio.
-
Sync the project with Gradle files.
-
Run the tests using the built-in test runner.
src/main/kotlin // Application code
src/test/kotlin // Unit tests
Key files and folders:
LeadsController
: Core class managing leads data.LeadsControllerTest
: Unit tests forLeadsController
.
The project includes extensive unit tests covering:
- Validation logic
- Adding valid and invalid leads
- Handling duplicates
Tests for coroutines and flows ensure:
- Proper handling of asynchronous code
- Correct emission of data streams
Example:
@Test
fun `should emit expected values from flow`() {
val flow = leadsController.getLeadsFlow()
testCoroutineScope.runBlockingTest {
val values = flow.toList()
assertEquals(expectedValues, values)
}
}
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Commit your changes with clear messages.
- Submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
Developed by Mohamed Elgohary. Feel free to connect on LinkedIn.