<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Daniel Gehrer on Medium]]></title>
        <description><![CDATA[Stories by Daniel Gehrer on Medium]]></description>
        <link>https://medium.com/@daniel.gehrer?source=rss-9bddfacdd72f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8E1nKpoLWmRHbi6LI_RFcA.jpeg</url>
            <title>Stories by Daniel Gehrer on Medium</title>
            <link>https://medium.com/@daniel.gehrer?source=rss-9bddfacdd72f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 23:43:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@daniel.gehrer/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to analyze transitive Java dependencies]]></title>
            <link>https://medium.com/monsterculture/how-to-analyze-transitive-java-dependencies-3d1334c6e772?source=rss-9bddfacdd72f------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d1334c6e772</guid>
            <category><![CDATA[maven]]></category>
            <category><![CDATA[dependencies]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Daniel Gehrer]]></dc:creator>
            <pubDate>Fri, 24 Apr 2020 12:17:58 GMT</pubDate>
            <atom:updated>2020-04-24T12:22:25.810Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KEdv-APNL4aYb-2Ll_9vpA.jpeg" /></figure><p>We stand on the shoulders of giants. Most of our code relies on code from others that we use as libraries. In <em>gradle</em> we can include such libraries as simple as adding implementation &quot;another.library:that-i-can-use:1.0.0&quot; to the build.gradle. Most of those libraries, again, build on top of yet other libraries. In the end, our code indirectly depends on way more libraries than we might think. Those indirect dependencies are also called <em>transitive dependencies</em>.</p><p>We have some tools to investigate those dependencies. For example in <em>Android Studio </em>(and other <a href="https://www.jetbrains.com/idea/">IDEA</a> based IDEs) we can analyze dependencies (including transitive dependencies) in the <em>Project Structure</em> window:</p><p>Open the <em>Project Structure </em>window via <em>Find Action</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jFgshkS1yRGIdTlJa6VOog.png" /><figcaption>Press ⌘+⇧+A / Ctrl+⇧+A to open “Find Action” and type “project structure”</figcaption></figure><p>In the <em>Project Structure</em> window select the <em>Dependencies-</em>tab on the left and chose a module (the modules may take a few seconds to load). Under <em>Resolved Dependencies</em> on the right, you can now browse the dependency tree:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c3m3WIRPjNAdcQxb6mAHvw.png" /></figure><p>If you prefer the command-line, you can use <em>gradle</em> to print a dependency tree:</p><pre>./gradlew :module-name:dependencies</pre><p>The output looks something like this:</p><pre>debugRuntimeClasspath - Runtime classpath of compilation &#39;debug&#39; (target  (androidJvm)).<br>+--- com.android.support:multidex:1.0.1 -&gt; androidx.multidex:multidex:2.0.0<br>+--- org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.3.61<br>|    \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.61 -&gt; 1.3.70<br>|         +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.70<br>|         \--- org.jetbrains:annotations:13.0<br>+--- org.jetbrains.kotlin:kotlin-stdlib:1.3.61 -&gt; 1.3.70 (*)<br>+--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5<br>|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.70 (*)<br>|    \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.70<br>\--- androidx.constraintlayout:constraintlayout:1.1.3<br>     \--- androidx.constraintlayout:constraintlayout-solver:1.1.3</pre><p>I also like to browse <a href="https://mvnrepository.com/">mvnrepository.com</a>. It makes it very easy to see transitive dependencies and follow them with a single click:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DFVu0MI0Ra8koErQP4jh9w.png" /></figure><p>As we saw, we do not only depend on a few libraries but on fully-fledged library trees. I hope this post introduced you to your new favorite way of analyzing dependencies. Have fun!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d1334c6e772" width="1" height="1" alt=""><hr><p><a href="https://medium.com/monsterculture/how-to-analyze-transitive-java-dependencies-3d1334c6e772">How to analyze transitive Java dependencies</a> was originally published in <a href="https://medium.com/monsterculture">Monster Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use Mockito together with MockK in Android instrumentation tests]]></title>
            <link>https://medium.com/monsterculture/how-to-use-mockito-together-with-mockk-in-android-instrumentation-tests-c8d022fac04e?source=rss-9bddfacdd72f------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8d022fac04e</guid>
            <category><![CDATA[maven]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mockk]]></category>
            <category><![CDATA[mockito]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Daniel Gehrer]]></dc:creator>
            <pubDate>Fri, 24 Apr 2020 12:16:13 GMT</pubDate>
            <atom:updated>2020-04-24T15:55:15.073Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Y0_bHpm2FptkBM_8Hn8Jw.jpeg" /></figure><p><strong>tl;dr:</strong> If you want to use both <em>Mockito</em> and <em>Mock</em>K in the same Android instrumentation test, use this configuration:</p><pre>androidTestImplementation &quot;io.mockk:mockk-android:1.10.0&quot;<br>androidTestImplementation(&quot;org.mockito:mockito-android:3.3.3&quot;) {<br>    exclude group: &quot;net.bytebuddy&quot;, module: &quot;byte-buddy-android&quot;<br>}<br>androidTestImplementation &quot;net.bytebuddy:byte-buddy-android:1.10.9&quot;</pre><h3>Background</h3><p>We at mySugr use <em>Mockito</em> already for years. Mockito feels a bit clunky when writing Kotlin-style code and sometimes workarounds and wrappers are needed. Since we’re using <em>Kotlin</em> and especially <em>Coroutines</em> more and more, we need another mocking framework that has first-class support for <em>Coroutines</em> and other <em>Kotlin</em> features. We chose <em>MockK</em>. Migrating all existing tests to <em>MockK</em> is not really an option. There are just too many of them. And there is not really a value added in doing so. So we decided to use <em>MockK</em> and <em>Mockito</em> in parallel. We use <em>MockK</em> for new tests and keep <em>Mockito</em> for existing tests. This works well for unit tests, but for instrumentation tests on Android, we got strange exceptions like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc582b03ff03cfe462d549c2329a6bc8/href">https://medium.com/media/bc582b03ff03cfe462d549c2329a6bc8/href</a></iframe><p>NoSuchFieldError means that a field that should exist isn&#39;t. This is a strong indicator that some dependencies got messed up. That can easily happen when the included libraries have transitive dependencies to different versions of the same library. In Java, each library (more precisely each <a href="https://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html">fully qualified name</a>) can only exist once. That means if e.g. <em>MockK</em> and <em>Mockito</em> both depend on different versions of another library, only one version is loaded. Which version exactly is loaded is decided by <em>gradle</em>. <a href="https://docs.gradle.org/current/userguide/dependency_resolution.html">Gradle resolves such version conflicts automatically under the hood by default</a>.</p><p>In our case, the version conflict resolution led to a runtime crash. Because the version that was included had breaking changes to the other version. Their result was that an expected field couldn’t be found.</p><h3>Investigation</h3><p>To find the library that causes problems, we need to investigate further. From the error, No instance field targetApiLevel of type I in class Lcom/android/dx/dex/DexOptions we know that the field is missing in the class com.android.dx.dex.DexOptions. So this class must be in the library where the wrong version is loaded. Android Studio helps because it can not only find classes in our own projects, but also in dependencies. Press ⌘+O/Ctrl+N, type com.android.dx.dex.DexOptions , and make sure <em>&quot;All places&quot;</em> is selected at the top.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HbQdgGD8Wr2-cHyM2lbWdg.png" /></figure><p>When the file is opened, we can see in the <em>Project View</em> that the class is located in the dependency com.jakewharton.android.repackaged:dalvik-dx:1:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*vpllHUoMWOTHDta7Ia-E2w.png" /></figure><p>Our assumption is now that a version of com.jakewharton.android.repackaged:dalvik-dx is present at runtime, where a needed field is missing that is needed by either <em>Mockito</em> or <em>MockK</em>. After <a href="https://medium.com/@daniel.gehrer/how-to-analyze-transitive-dependencies-3d1334c6e772">investigating transitive dependencies (instructions here)</a>, we see that there is really a version mismatch.</p><p>This is how the transitive path to the dalvik-dx dependency looks like (&quot;→&quot; means <em>depends on</em>):</p><p><em>MockK:</em> io.mockk:mockk-android:1.10.0 → io.mockk:mockk-agent-android:1.10.0 → com.linkedin.dexmaker:dexmaker:2.21.0 → com.jakewharton.android.repackaged:dalvik-dx:9.0.0_r3</p><p><em>Mockito:</em> org.mockito:mockito-android:3.3.3 → net.bytebuddy:byte-buddy-android:1.10.5 → com.jakewharton.android.repackaged:dalvik-dx:1</p><p>We see that <em>MockK</em> depends on dalvik-dx version 9.0.0_r3 , and <em>Mockito</em> on version 1 .</p><p>After investigating further, we see that targetApiLevel field is actually gone in dalvik-dx:9.0.0_r3. So we found the issue! But what&#39;s next? The best idea would be to check if the newest version of mockito-android depends (transitively) on the same dalvik-dx version as mockk-android. Unfortunately, at the moment there is no newer version for mockito-android. However, there is a newer version of byte-buddy-android ( 1.10.9) that depends on dalvik-dx:9.0.0_r3. The best way to upgrade that dependency would be to contribute to the <em>Mockito</em> open source project and wait for the next release. Until the next release with the updated dependency is ready, we can do a little hack: We tell <em>gradle</em> to not include byte-buddy-android from <em>Mockito</em>, but instead, we provide the newer version:</p><pre>androidTestImplementation(&quot;org.mockito:mockito-android:3.3.3&quot;) {<br>    exclude group: &quot;net.bytebuddy&quot;, module: &quot;byte-buddy-android&quot;<br>}<br>androidTestImplementation &quot;net.bytebuddy:byte-buddy-android:1.10.9&quot;</pre><p>Note that the exclude group is necessary for all dependencies that include byte-buddy-android, otherwise the same dependency may sneak in via another transitive dependency.</p><p>After running the tests again, all tests succeed without the error. We fixed the problem!</p><h3>Conclusion</h3><p>We learned how we find the library where an incompatible version is loaded and how to replace it using <em>gradle</em>. In this example, we were very lucky. Because the change in the version of byte-buddy-android from 1.10.5 to 1.10.9 is only a patch, meaning there aren&#39;t any breaking changes. If that isn&#39;t the case, we might get a new error, where another field or method is missing. Version conflicts are usually very nasty and not as easily resolved as in this case. Especially in production code, I advise you to avoid such &quot;dependency replacements&quot; as much as possible since it can lead to subtle runtime crashes that are hard to track down.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8d022fac04e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/monsterculture/how-to-use-mockito-together-with-mockk-in-android-instrumentation-tests-c8d022fac04e">How to use Mockito together with MockK in Android instrumentation tests</a> was originally published in <a href="https://medium.com/monsterculture">Monster Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Reproduce Flaky Tests in Android Studio]]></title>
            <link>https://medium.com/monsterculture/reproduce-flaky-tests-b8b42306d23f?source=rss-9bddfacdd72f------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8b42306d23f</guid>
            <category><![CDATA[flaky]]></category>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[android-studio]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Daniel Gehrer]]></dc:creator>
            <pubDate>Fri, 13 Mar 2020 10:46:10 GMT</pubDate>
            <atom:updated>2020-03-13T10:54:18.896Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C540DEJawZXedmTHBjfgGQ.jpeg" /></figure><p>Flaky tests are a pain. If the tests sometimes succeed and sometimes fail without changing any code, the developers stop trusting the tests. If developers cannot trust the tests, <a href="https://medium.com/scopedev/how-can-we-peacefully-co-exist-with-flaky-tests-3c8f94fba166">they cannot trust the code and eventually the product and the company</a>.</p><p>One reason why flaky tests are hard to fix is that they are hard to reproduce. Fortunately, Android Studio has our back and provides a tool that helps with it: <em>Repeat Until Failure</em>. This is how you can use it:</p><p>We have identified a flaky test. It succeeds 99% of the time but we get some failures from time to time:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DYW5_EAa5UV1NnLRv9fK2Q.png" /></figure><p>Click on the small green arrow on the left-hand side of the test to run it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H1BwgDQqSIibDZmvdXkFVg.png" /></figure><p>By running the test, Android Studio automatically creates a <em>“Run/Debug Configuration”</em> for that test. To let the test run until it fails, we need to edit that configuration:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WgFopQ_5T_SgQDkauOiffQ.png" /></figure><p>The configuration edit window pops up where we can set the “Repeat” property to “Until Failure”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xUqBOTGgJ1SfWezEeVAgGw.png" /></figure><p>Click on OK and then press the “Run” button in the toolbar next to the configuration. Or just use the shortcut: <em>^R</em> (Mac) or <em>Shift + F10</em> (Windows, Linux). The test now runs until it fails:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kBnUU1l_nPDuscxSxcInFQ.png" /></figure><p>We get a little report for every run. In this case, the test succeeded 89 times and then failed for the first time. We get the stack trace of the error that occurred and it might be a good idea to add some additional debug messages to the code.</p><p>That’s it. Have fun to reproduce and fix your flaky tests!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8b42306d23f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/monsterculture/reproduce-flaky-tests-b8b42306d23f">How To Reproduce Flaky Tests in Android Studio</a> was originally published in <a href="https://medium.com/monsterculture">Monster Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>