https://github.com/aliiiw/test-learning
this is repo for flash back to testing :)
https://github.com/aliiiw/test-learning
android espresso junit4 mockito mockk-android roboelectric unit-testing
Last synced: about 1 month ago
JSON representation
this is repo for flash back to testing :)
- Host: GitHub
- URL: https://github.com/aliiiw/test-learning
- Owner: Aliiiw
- Created: 2024-08-06T10:36:16.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-12T09:30:08.000Z (almost 2 years ago)
- Last Synced: 2025-01-30T00:31:44.247Z (over 1 year ago)
- Topics: android, espresso, junit4, mockito, mockk-android, roboelectric, unit-testing
- Language: Kotlin
- Homepage:
- Size: 108 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Test-Learning
Test-Learning is an Android/Kotlin practice project focused on unit testing fundamentals. It contains small, testable classes for arithmetic, registration validation, string assertions, and repository/service interactions with mocks.
## What This Project Covers
- Basic JUnit tests.
- Google Truth fluent assertions.
- Mockito and Mockito-Kotlin mocks.
- Testing simple business logic.
- Testing validation rules.
- Testing repository behavior against a mocked service.
- Android project setup with ViewBinding enabled.
## Tech Stack
- Kotlin
- Android XML/View system
- AppCompat
- ViewBinding
- JUnit 4
- Google Truth
- Mockito Core
- Mockito-Kotlin
- Espresso / AndroidX test dependencies
## Project Structure
```text
app/src/main/java/ir/alirahimi/testapp
├── Calculator.kt # Simple arithmetic methods
├── RegistrationUtil.kt # Registration validation rules
├── MainActivity.kt # Minimal Android activity
└── data
├── local/User.kt # User data model
├── service/UserService.kt # In-memory user source
└── repository/UserRepository.kt
app/src/test/java/ir/alirahimi/testapp
├── CalculatorTest.kt
├── RegistrationUtilTest.kt
├── StringTest.kt
├── UserRepositoryTest.kt
├── MainActivityTest.kt
└── ExampleUnitTest.kt
```
## Tested Logic
### Calculator
The calculator supports:
- Addition
- Subtraction
- Multiplication
- Integer division
- Division-by-zero protection in production code
### Registration Validation
`RegistrationUtil` returns invalid when:
- Username is empty.
- Password is empty.
- Username already exists.
- Password confirmation does not match.
- Password contains fewer than two digits.
### Repository Tests
`UserRepositoryTest` uses Mockito to mock `UserService` and verify that repository methods call the expected service methods for:
- Get user by ID
- Get user by name
- Get user by email
- Get all users
- Invalid user lookup
## Running Tests
```bash
./gradlew test
```
For Android instrumentation tests:
```bash
./gradlew connectedAndroidTest
```
## Getting Started
1. Clone the repository.
2. Open it in Android Studio.
3. Sync Gradle.
4. Run the unit tests from Android Studio or with Gradle.
## Notes
This repository is intentionally small and focused on testing practice, not on building a full user-facing Android app.