|
| 1 | +# Kotlin Testing Frameworks |
| 2 | + |
| 3 | +## ✅ Unit Testing & JVM Testing |
| 4 | +### 1. JUnit 5 (Jupiter) - Standard JVM Testing |
| 5 | +- Best for unit and integration tests. |
| 6 | +- Supports annotations like `@Test`, `@BeforeEach`, `@AfterEach`. |
| 7 | +- Works well with Kotest, Mockito, and Spring. |
| 8 | + |
| 9 | +### 2. Kotest (formerly KotlinTest) - Kotlin-native Testing |
| 10 | +- Supports property-based testing, matchers, and coroutines. |
| 11 | +- DSL-style syntax for expressive tests. |
| 12 | + |
| 13 | +### 3. Spek - Specification-based Testing |
| 14 | +Inspired by RSpec (from Ruby). |
| 15 | + |
| 16 | +## ✅ Mocking Libraries |
| 17 | +### 4. Mockito & MockK - Mocking Frameworks |
| 18 | +- Mockito: Java-based, integrates with JUnit 5. |
| 19 | +- MockK: Kotlin-native, better for coroutines and DSL-friendly. |
| 20 | + |
| 21 | +## ✅ Android UI & Instrumentation Testing |
| 22 | +### 5. Espresso - UI Testing for Android |
| 23 | + |
| 24 | +### 6. UIAutomator - System UI Testing |
| 25 | +Used for interactions beyond the app (e.g., system UI, notifications). |
| 26 | +### 7. Compose Testing - Jetpack Compose UI Testing |
| 27 | + |
| 28 | +## ✅ Benchmarking & Performance Testing |
| 29 | +### 8. JMH (Java Microbenchmark Harness) - Benchmark Kotlin Code |
| 30 | +Best for measuring performance of functions and loops. |
| 31 | +Requires annotation processing (kapt). |
| 32 | + |
| 33 | +### 9. Android Benchmark (Jetpack) |
| 34 | +Measures Android performance in native/kotlin code. |
| 35 | +Supports BenchmarkRule and Perfetto. |
| 36 | + |
| 37 | +## ✅Turbine |
| 38 | +Works with kotlinx.coroutines.Flow for testing emissions. |
| 39 | +Eliminates the need for complex collect() calls in tests. |
| 40 | +Supports structured assertions like awaitItem(), expectNoEvents(), and awaitComplete(). |
| 41 | + |
| 42 | +### ✅ Turbine vs Standard Flow Testing |
| 43 | + |
| 44 | +| Feature | Standard Flow (`collect`) | Turbine | |
| 45 | +|----------------------------------|-----------------|---------| |
| 46 | +| Requires manual `collect()` | ✅ Yes | ❌ No | |
| 47 | +| Assertions are simple | ❌ No | ✅ Yes | |
| 48 | +| Supports awaiting specific items | ❌ No | ✅ Yes (`awaitItem()`) | |
| 49 | +| Checks for no events | ❌ No | ✅ Yes (`expectNoEvents()`) | |
| 50 | +| Supports Flow cancellation | ❌ No | ✅ Yes (`cancelAndIgnoreRemainingEvents()`) | |
| 51 | +| Handles delays in Flows | ❌ No | ✅ Yes | |
0 commit comments