Skip to content

Commit 0245bdf

Browse files
committed
Add Phase 3 tests for Async Operations
Implement comprehensive test coverage for async coroutine-based worker jobs that handle image loading and cropping. This phase ensures async operations handle errors gracefully, manage memory correctly, and respect lifecycle properly. **New Test Files (33 tests total):** TestCoroutineExtensions.kt (Test Helper) - CoroutineTestRule for managing test dispatchers - Automatic setup/teardown of Main dispatcher - TestScope and UnconfinedTestDispatcher for immediate execution BitmapLoadingWorkerJobTest.kt (19 tests) - Successful loading flow with EXIF orientation - Error handling (decode failures, EXIF read failures) - Density calculation (high DPI adjustment, low DPI passthrough) - Coroutine lifecycle (start, cancel, isActive checks) - WeakReference memory management - EXIF orientation support (0°, 90°, 180°, 270°) - EXIF flip support (horizontal, vertical, combined) - Sample size propagation BitmapCroppingWorkerJobTest.kt (14 tests) - URI-based cropping with all parameters - Bitmap-based cropping with OOM handling - Error handling (cropping failures, write failures) - Null input handling (empty results) - Coroutine lifecycle (cancellation prevents callback) - Memory management (bitmap recycling when callback not invoked) - Resize operations with RequestSizeOptions - Compression format support (JPEG, PNG) - Custom output URI handling - Sample size propagation **CI Timeout Configuration:** Add sensible timeouts to prevent jobs from hanging indefinitely: - gradle-wrapper-validation: 2 minutes - Build jobs: 10 minutes each - License/Lint checks: 5 minutes - Android Lint: 10 minutes - Unit Tests: 15 minutes (for all 167 tests) Timeouts are 2-3x typical execution time to account for runner variability and cache misses while ensuring faster failure detection. **PLAN.md Updates:** - Marked Phase 3 ✅ Complete - Fixed Phase 2 test count (65 tests, not 45) - Updated total: 167 tests across 9 test files - Added completed test files list with Phase 3 entries **Key Testing Patterns:** - MockK for mocking BitmapUtils static methods - Robolectric for Android context - Coroutine test library for deterministic async testing - Slot capture for verifying callback parameters - UnconfinedTestDispatcher for immediate execution (no advanceUntilIdle needed) This is Phase 3 of the 8-phase plan, focusing on bulletproof async operation testing with coroutines.
1 parent 3bdc72c commit 0245bdf

7 files changed

Lines changed: 1354 additions & 13 deletions

File tree

.github/workflows/ci-build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jobs:
1111
build-library:
1212
name: Build Library (JDK ${{ matrix.java_version }})
1313
runs-on: macOS-latest
14+
timeout-minutes: 10
1415

1516
strategy:
1617
matrix:
@@ -43,6 +44,7 @@ jobs:
4344
build-sample:
4445
name: Build Sample App (JDK ${{ matrix.java_version }})
4546
runs-on: macOS-latest
47+
timeout-minutes: 10
4648

4749
strategy:
4850
matrix:

.github/workflows/ci-tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jobs:
1111
license-check:
1212
name: License Check
1313
runs-on: macOS-latest
14+
timeout-minutes: 5
1415

1516
steps:
1617
- name: Checkout code
@@ -32,6 +33,7 @@ jobs:
3233
ktlint:
3334
name: Kotlin Lint (ktlint)
3435
runs-on: macOS-latest
36+
timeout-minutes: 5
3537

3638
steps:
3739
- name: Checkout code
@@ -53,6 +55,7 @@ jobs:
5355
lint:
5456
name: Android Lint
5557
runs-on: macOS-latest
58+
timeout-minutes: 10
5659

5760
steps:
5861
- name: Checkout code
@@ -84,6 +87,7 @@ jobs:
8487
unit-tests:
8588
name: Unit Tests (JDK ${{ matrix.java_version }})
8689
runs-on: macOS-latest
90+
timeout-minutes: 15
8791

8892
strategy:
8993
matrix:

.github/workflows/gradle-wrapper-validation.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jobs:
1111
validation:
1212
name: Validate Gradle Wrapper
1313
runs-on: ubuntu-latest
14+
timeout-minutes: 2
1415

1516
steps:
1617
- name: Checkout code

PLAN.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
**Created:** 2026-04-23
44
**Last Updated:** 2026-04-24
5-
**Status:** In Progress - Phase 2 Complete
5+
**Status:** In Progress - Phase 3 Complete
66
**Goal:** Achieve comprehensive test coverage to catch bugs before CI/release
77

88
---
@@ -12,24 +12,27 @@
1212
| Phase | Status | Tests Added | Description |
1313
|-------|--------|-------------|-------------|
1414
| **Phase 1** |**Complete** | 69 tests | Security Foundation - URI and file handling |
15-
| **Phase 2** |**Complete** | 48 tests | Configuration & Options validation |
16-
| **Phase 3** | ⏳ Pending | - | Async Operations (coroutines) |
15+
| **Phase 2** |**Complete** | 65 tests | Configuration & Options validation |
16+
| **Phase 3** | **Complete** | 33 tests | Async Operations (coroutines, worker jobs) |
1717
| **Phase 4** | ⏳ Pending | - | Core Bitmap Operations |
1818
| **Phase 5** | ⏳ Pending | - | Crop Window Logic |
1919
| **Phase 6** | ⏳ Pending | - | UI Components |
2020
| **Phase 7** | ⏳ Pending | - | Public API |
2121
| **Phase 8** | ⏳ Pending | - | Supporting Features |
2222

23-
**Total Tests:** 117 tests across 6 test files
23+
**Total Tests:** 167 tests across 9 test files
2424
**Coverage Target:** 70-80% overall, 90%+ for critical security files
2525

2626
### Completed Test Files
2727
-`GetFilePathFromUriTest.kt` (27 tests) - Phase 1
2828
-`GetUriForFileTest.kt` (25 tests) - Phase 1
2929
-`BitmapUtilsTest.kt` (17+ tests expanded) - Phase 1
3030
-`CropImageOptionsTest.kt` (33 tests) - Phase 2
31-
-`CropExceptionTest.kt` (11 tests) - Phase 2
31+
-`CropExceptionTest.kt` (8 tests) - Phase 2
3232
-`ParcelableUtilsTest.kt` (24 tests) - Phase 2
33+
-`BitmapLoadingWorkerJobTest.kt` (19 tests) - Phase 3
34+
-`BitmapCroppingWorkerJobTest.kt` (14 tests) - Phase 3
35+
-`TestCoroutineExtensions.kt` (test helper) - Phase 3
3336

3437
---
3538

@@ -999,22 +1002,22 @@ Create `cropper/src/test/resources/`:
9991002
**Goal:** Ensure configuration validation is bulletproof
10001003

10011004
4.`CropImageOptionsTest.kt` (33 tests) - All validation rules, boundary values, Parcelable
1002-
5.`CropExceptionTest.kt` (11 tests) - Exception hierarchy, messages, serialization
1005+
5.`CropExceptionTest.kt` (8 tests) - Exception hierarchy, messages, serialization
10031006
6.`ParcelableUtilsTest.kt` (24 tests) - Bundle/Intent extraction, type safety
10041007

1005-
**Deliverable:** ✅ Configuration cannot be misconfigured, exceptions well-tested (48 total tests)
1008+
**Deliverable:** ✅ Configuration cannot be misconfigured, exceptions well-tested (65 total tests)
10061009

10071010
---
10081011

1009-
### Phase 3: Async Operations (Week 2)
1012+
### Phase 3: Async Operations **COMPLETE**
10101013
**Goal:** Async jobs handle errors gracefully
10111014

1012-
7. Add `kotlinx-coroutines-test` dependency
1013-
8. Create `TestCoroutineExtensions.kt` helper
1014-
9. `BitmapLoadingWorkerJobTest.kt` (3-4 days)
1015-
10. `BitmapCroppingWorkerJobTest.kt` (4 days)
1015+
7. `kotlinx-coroutines-test` dependency (already added in Phase 1)
1016+
8. `TestCoroutineExtensions.kt` helper - CoroutineTestRule for dispatcher setup
1017+
9. `BitmapLoadingWorkerJobTest.kt` (19 tests) - Loading, EXIF, density, lifecycle, errors
1018+
10. `BitmapCroppingWorkerJobTest.kt` (14 tests) - URI/Bitmap cropping, memory, lifecycle, errors
10161019

1017-
**Deliverable:** All async operations tested with cancellation, errors, lifecycle
1020+
**Deliverable:** All async operations tested with cancellation, errors, lifecycle (33 total tests)
10181021

10191022
---
10201023

0 commit comments

Comments
 (0)