|
134 | 134 | * |
135 | 135 | * With Mockito version 2.6.1 we ship "native" Android support. To enable Android support, add the `mockito-android` library as dependency |
136 | 136 | * to your project. This artifact is published to the same Mockito organization and can be imported for Android as follows: |
| 137 | + * <p> |
| 138 | + * Version catalog: |
| 139 | + * <pre class="code"><code class="toml"> |
| 140 | + * [versions] |
| 141 | + * mockito = "5.23.0" |
137 | 142 | * |
138 | | - * <pre class="code"><code> |
139 | | - * repositories { |
140 | | - * mavenCentral() |
141 | | - * } |
| 143 | + * [libraries] |
| 144 | + * mockito = { module = "org.mockito:mockito-core", version.ref = "mockito" } |
| 145 | + * mockito-android = { module = "org.mockito:mockito-android", version.ref = "mockito" } |
| 146 | + * </code></pre> |
| 147 | + * App Gradle file: |
| 148 | + * <pre class="code"><code class="kotlin"> |
142 | 149 | * dependencies { |
143 | | - * testCompile "org.mockito:mockito-core:+" |
144 | | - * androidTestCompile "org.mockito:mockito-android:+" |
| 150 | + * testImplementation(libs.mockito) |
| 151 | + * androidTestImplementation(libs.mockito.android) |
145 | 152 | * } |
146 | 153 | * </code></pre> |
| 154 | + * <p> |
| 155 | + * <b>New in Mockito 5.23.0 - Kotlin support!</b> The `mockito-android` artifact now uses |
| 156 | + * <a href="https://github.com/linkedin/dexmaker">dexmaker-mockito-inline</a> under the hood to provide inline mocking on Android, |
| 157 | + * which supports mocking of final classes and methods. This means it can mock Kotlin classes without having to mark them as {@code open}. |
| 158 | + * |
| 159 | + * <p> |
| 160 | + * Note this requires Android API 28 (Android P) or higher at runtime. Apps with a lower |
| 161 | + * {@code minSdk} will still compile, but tests will fail if run on an emulator or device with an API level below 28. |
147 | 162 | * |
148 | | - * You can continue to run the same unit tests on a regular VM by using the `mockito-core` artifact in your "testCompile" scope as shown |
149 | | - * above. Be aware that you cannot use the <a href="#39">inline mock maker</a> on Android due to limitations in the Android VM. |
| 163 | + * <p> |
| 164 | + * Note you must set {@code android:extractNativeLibs="true"} in your {@code androidTest/AndroidManifest.xml} for the |
| 165 | + * dexmaker native library to be accessible: |
| 166 | + * |
| 167 | + * <pre class="code"><code> |
| 168 | + * <application android:extractNativeLibs="true" /> |
| 169 | + * </code></pre> |
150 | 170 | * |
151 | | - * If you encounter issues with mocking on Android, please open an issue |
152 | | - * <a href="https://github.com/mockito/mockito/issues/new">on the official issue tracker</a>. |
153 | | - * Do provide the version of Android you are working on and dependencies of your project. |
| 171 | + * Using `mockito-android` in a non-Android environment is unsupported. For JVM tests, use `mockito-core` directly. |
154 | 172 | * |
155 | 173 | * <h3 id="0.2">0.2. <a class="meaningful_link" href="#mockito-inline" name="mockito-inline">Configuration-free inline mock making</a></h3> |
156 | 174 | * |
|
1143 | 1161 | * <p>Driven by requirements and patches from Google Android guys Mockito now offers an extension point |
1144 | 1162 | * that allows replacing the proxy generation engine. By default, Mockito uses <a href="https://github.com/raphw/byte-buddy">Byte Buddy</a> |
1145 | 1163 | * to create dynamic proxies. |
1146 | | - * <p>The extension point is for advanced users that want to extend Mockito. For example, it is now possible |
1147 | | - * to use Mockito for Android testing with a help of <a href="https://github.com/crittercism/dexmaker">dexmaker</a>. |
1148 | 1164 | * <p>For more details, motivations and examples please refer to |
1149 | 1165 | * the docs for {@link org.mockito.plugins.MockMaker}. |
1150 | 1166 | * |
|
0 commit comments