<?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 Hartwich on Medium]]></title>
        <description><![CDATA[Stories by Daniel Hartwich on Medium]]></description>
        <link>https://medium.com/@hartwich.daniel?source=rss-afc3af7716b5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*CTkWZQ_cBiuZcrZOwMTrpA.jpeg</url>
            <title>Stories by Daniel Hartwich on Medium</title>
            <link>https://medium.com/@hartwich.daniel?source=rss-afc3af7716b5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 05:56:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hartwich.daniel/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[Running Android Espresso Tests with Data Binding (and koin)]]></title>
            <link>https://medium.com/freenet-engineering/running-android-espresso-tests-with-data-binding-and-koin-a57a8d38daa5?source=rss-afc3af7716b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/a57a8d38daa5</guid>
            <category><![CDATA[app-development]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[data-binding]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-development]]></category>
            <dc:creator><![CDATA[Daniel Hartwich]]></dc:creator>
            <pubDate>Mon, 29 Apr 2019 08:52:21 GMT</pubDate>
            <atom:updated>2019-04-29T08:56:02.953Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently, we at <a href="https://www.freenet.de/">freenet.de</a> started working on an application that uses the <a href="https://developer.android.com/topic/libraries/data-binding/">data binding library</a>.</p><p>Data binding was presented by <a href="https://www.youtube.com/watch?v=5sCQjeGoE7M">Google already in September 2015</a> but has evolved and improved quite a bit. It’s now officially part of <a href="https://developer.android.com/jetpack/">Android Jetpack</a> that we developers love to use in our projects in order to <em>reduce boilerplate, accelerate development </em>and <em>build high quality, robust apps.</em></p><p>For this application we had to build a feature that simply displays a list of items and of course we were using data binding for it.</p><p>Building the screen was fast and simple and with the help of data binding, we could just pass my items to the adapter and let the binding handle all the rendering and assigning of values to their respective views. So in no time we had the screen up and running and we were ready to submit a pull request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*1WW2L2V5I8hWyFlaCHb0yg.jpeg" /><figcaption>There’s always more to do!</figcaption></figure><h4>We hadn’t thought about tests yet (well, we kind of had already 😉)</h4><p>Of course, we wanted to have tests to ensure that everything <em>looks</em> as expected (UI tests) and that everything <em>works</em> as expected (Unit tests). While Unit tests were easy to write and through <a href="https://site.mockito.org/">mockito</a> we can mock the dependencies to other components, it was not straightforward when we wanted to write UI tests.</p><p><strong>Things got interesting when we tried to write espresso tests…</strong></p><p>Well, in theory it should be easy, because all we need to do is mock the ViewModel, that is emitting view states, which will be rendered by the activity (or fragment) and afterwards make sure that the expected data is visible.</p><p>Turns out this is easier said than done:</p><p><strong>How to make sure that the activity you are starting uses your ViewModel instance?</strong></p><p>In the application we are working on we are using <a href="https://github.com/InsertKoinIO/koin">koin</a> to inject our dependencies. Through this, we are also injecting our view models into our fragments and activities, and this is where we need to hook in. In the setup block of our espresso test we can add our view model to the dependency tree by calling loadKoinModule().</p><p>It’s also important to say that in order to override koin modules that are implemented in the Main App, you should have a custom TestApplication and a custom JUnitRunner (check out the example that is linked below to see how to do it).</p><p>So now, we just need to observe changes of our LiveData&lt;ViewState&gt; and check that the changes get rendered as expected. This worked fine in the beginning, but after adding a few more tests, we ran into issues, that the tests became flaky, because the data binding had not finished yet and we worked around this by putting Thread.sleep(400) in our tests as a quick fix. But this is not the solution we want. We want something more optimal, so we began researching… After a short amount of time we found <a href="https://stackoverflow.com/a/52390905">this</a> Stack Overflow answer, that gave us the much needed hint:</p><blockquote>Espresso does waitForIdle before executing view checks. waitForIdle goes thought IdlingRegistry and waits until every IdlingResource is idle.</blockquote><blockquote>LoopingIdlingResource is used in Espresso by default. It waits until looper doesn&#39;t have messages in queue, which means that it is idle.</blockquote><blockquote>However DataBinding uses different approach to schedule an update, it uses Choreographer.postFrameCallback. So updates are not posted into looper queue and Espresso will not wait for them.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/120/1*UV40YyFJkUlAnROtJ8iOVg.png" /></figure><p>This means, we need our own IdlingResource that looks at our data bindings and allows the test to proceed when all the data binding is finished. Luckily in the same answer, there were also two links to a google-samples repository that already had a partial a solution for our problem:</p><p>A <a href="https://github.com/googlesamples/android-architecture-components/blob/7f861fd45d158e6277a3c35163c7f663e135b2cf/GithubBrowserSample/app/src/androidTest/java/com/android/example/github/util/DataBindingIdlingResource.kt">DatabindingIdlingResource</a> that works for Fragments and a <a href="https://github.com/googlesamples/android-architecture-components/blob/7f861fd45d158e6277a3c35163c7f663e135b2cf/GithubBrowserSample/app/src/androidTest/java/com/android/example/github/util/DataBindingIdlingResourceRule.kt">DatabindingIdlingResourceRule</a> that needs to be applied in our test in order to wait for the DatabindingIdlingResource to idle.</p><p>The only remaining problem is, that we need the DatabindingIdlingResource to also wait for Activities.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/628c61ccb2f4b1457536dbfeb5a923a5/href">https://medium.com/media/628c61ccb2f4b1457536dbfeb5a923a5/href</a></iframe><p>Now it works with activities and fragments…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*qD4s47WEYb-31O3g_rdZnA.jpeg" /><figcaption>One more… oh yea 🎉</figcaption></figure><p>After applying the new IdlingResource in our test we were happy and we thought the tests would finally all be green, but just shortly after running them 2 or 3 times we figured out, that they are still broken / flaky. What were we missing?</p><p>And then it struck us… The adapter is also using data binding so we have something like a data bindingception.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*FCaMKDO45sdo1v2bDKzEIg.jpeg" /></figure><p>So one last step to get our tests to run is to wait for all the children of theRecyclerView to finish their binding before we run our test assertions:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7acd91d4d17303013068848c247ab7fa/href">https://medium.com/media/7acd91d4d17303013068848c247ab7fa/href</a></iframe><p>And that’s it… now Espresso waits until all data bindings have been finished before it starts executing.</p><p>We thought this is a nice and small piece of information to share that can be really helpful when you want to write Espresso tests (kudos to you already) and you are using data binding + koin.</p><p>Feel free to check out the small <a href="https://github.com/dhartwich1991/databinding-espresso">example project on GitHub</a> we created and if this article helped you to solve a problem or you just enjoyed reading it, feel free to smash the clap button below to give me feedback. 👏</p><p>We are also more than happy to receive any kind of comments!</p><p><a href="https://github.com/dhartwich1991/databinding-espresso">dhartwich1991/databinding-espresso</a></p><p><em>Interested in how we develop software? </em><a href="https://stellenangebote.freenet-group.de/stellenangebote.html?sid=06aa4ffaee857ab350a7a7fcbb1061da"><em>Join our team in Hamburg, Germany!</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a57a8d38daa5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/freenet-engineering/running-android-espresso-tests-with-data-binding-and-koin-a57a8d38daa5">Running Android Espresso Tests with Data Binding (and koin)</a> was originally published in <a href="https://medium.com/freenet-engineering">freenet Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Docker for running Android Tests on your CI]]></title>
            <link>https://tech.new-work.se/using-docker-for-running-android-tests-on-your-ci-d10d94b1e680?source=rss-afc3af7716b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/d10d94b1e680</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[quality-assurance]]></category>
            <dc:creator><![CDATA[Daniel Hartwich]]></dc:creator>
            <pubDate>Wed, 19 Sep 2018 11:09:43 GMT</pubDate>
            <atom:updated>2018-09-19T11:10:30.711Z</atom:updated>
            <content:encoded><![CDATA[<p>At <a href="https://www.xing.com/">XING</a> we are around 30 Android developers that are contributing to the same app.</p><p>In the past six months, we invested a lot of time in making our espresso tests execution on our Jenkins CI server way more stable. In this article, I would like to share our story of how we got to stable espresso tests.</p><p>We rely heavily on running all of our unit tests and UI tests on each pull request to ensure that they are constantly green and no tests are broken.</p><p>While running unit tests from a terminal is quite simple, if you use tools like <a href="http://robolectric.org/">robolectric,</a> different architecture patterns and run them solely on the JVM, it’s quite a complex problem to run your <a href="https://developer.android.com/training/testing/espresso/">espresso</a> or other tests (like <a href="https://calaba.sh/">calabash</a> or <a href="http://appium.io/">appium</a>) that require a device to run from a command line interface.</p><h3>Running tests on real devices</h3><p>One solution would be to run these tests on real devices that are connected to the CI instance directly, but depending on your CI solution (we use <a href="https://jenkins.io/">Jenkins</a>) this might be a problem. Also, this will not scale well if you have multiple people creating or updating pull requests at the same time. Another problem is, that you probably would want to run on real devices that most of your users use. For XING that would be:</p><p>Most used devices for the XING Android App (July 2018)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*wkrAVz39pBA95rAEXKWlJQ.jpeg" /></figure><p>As you can tell from the chart above you want to connect Samsung devices to your CI server and run the tests on there. Good luck with that. It will be tough just to unlock all of these devices before running the tests. We had a similar set up in the past using a nice tool called <a href="https://openstf.io/">OpenSTF</a> that we integrated with our Jenkins but it was causing nothing but pure, sweet pain, when using it there. Another problem of the many we had was that we need to maintain potential adb failures that would occur regularly. In addition to that we started to see problems with power supply on our device farm as soon as we started adding more devices to it. Suddenly, devices would switch off or discharge at random.</p><p>We saw the failures, weren’t happy about them and decided we need something else because this approach just wouldn’t work and introduced way too much flakiness, where tests would randomly fail or not even start because the phone crashed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/1*RZL5jCKeszuvAndC6f-6CA.png" /><figcaption>Best definition of flakiness 🤷‍♀</figcaption></figure><h3>Using AVDs / emulators to run espresso tests</h3><p>Previously, we had also tried to run the espresso tests on AVDs (Android Virtual Devices), which made the tests more consistent, but introduced the problem of having to manage everything around them. Creating them, starting them, cleaning before running tests on them and killing them once they are done. While it seemed to be more stable in the beginning ,we now had to maintain a lot of bash scripts that tried to execute the necessary steps one after another which were really hard to write in the first place and almost impossible to change if we had to. In addition to that, the whole system was really vulnerable to inconsistencies, like early exits of tests or other unexpected events that could occur at any time.</p><p>Our team and the XING Android community said that time has come to put an end to this <em>insanity</em> and find a proper solution to our problem.</p><p>We looked at different technologies that could help us to solve our problem and finally ended up with <a href="https://www.docker.com/">Docker</a> which is a nice tool to run things really isolated within a so-called container on almost any machine. The idea was to create a docker container that has all Android dependencies that you need to build and run an Android app in it and that boots up a single AVD whenever it is started. So the rough plan for our CI was to:</p><ol><li>Start the docker container on our CI</li></ol><p>2. Include the project folder of our Android App in the container</p><p>3. Build the app inside the container</p><p>4. Run the tests inside the container</p><p>5. Return the results back to our Jenkins machine that hosted the docker container</p><p>Of course it would still require some sort of scripting to do that so we decided to take it even further and create a <a href="https://fastlane.tools/">fastlane</a> plugin that will handle all of these things for us.</p><p>That’s when we built <a href="https://github.com/xing/mango">mango</a>:</p><p><a href="https://github.com/xing/mango">xing/mango</a></p><p>mango is able to do all of the above mentioned work for you with just a simple fastlane task that you configure in your project:</p><pre>desc &quot;Run espresso tests on docker images&quot;<br>  lane :espresso_tests do<br>    run_dockerized_task(<br>      container_name: &quot;espresso_container&quot;,<br>      docker_image: &quot;joesss/mango-docker:latest&quot;,<br>      container_timeout: 120,<br>      android_task: &quot;./gradlew connectedAndroidTest&quot;,<br>      post_actions: &quot;adb logcat -d &gt; logcat.txt&quot;,<br>      pull_latest_image: true<br>    )<br>  end</pre><p>As you can see you just need to include the mango plugin using:</p><p>fastlane add_plugin mango</p><p>And you’ll get access to the run_dockerized_taskaction in your Fastfile.</p><p>In this action you just need to specify a few things like the docker_image, container_name and the android_task and you should be ready to go.</p><p>Alongside with this fastlane plugin we also published our Dockerfiles that we are using for ourselves and have proven to be working fine for our needs.</p><p><a href="https://github.com/xing/mango-docker">xing/mango-docker</a></p><p>Though the tests are now around 99% stable on each of the pull requests there are some nitpicks that you need to take care about if you want to use it on your CI:</p><ul><li>You have to use fastlane</li><li>We use ubuntu machines as our hosts for the docker containers. We experienced some problems if you try to run Qemu/kvm to emulate an Android CPU when running on macOS</li></ul><p>We are currently using 8x 24-Core machines connected to our Jenkins. This allows us to run <strong>160 </strong>docker tasks in parallel without exceeding the capabilities of our systems. This enabled us to run all unit tests (~7000), all integration (~600) and all of our espresso UI tests (~250) tests on every commit we do in around 15 minutes without having huge queues.</p><p>Through this, we get super fast feedback and make sure that all of our tests are run as early as possible because new code reaches the actual users.</p><p>So if you want to get started using mango or try it yourself just go ahead and do so :) If you hit any walls create an <a href="https://github.com/xing/mango/issues/new">issue</a> and ask for help there.</p><p>What do you think about our solution? How did you solve this problem for your team? Please make sure to let us know in the comments below!</p><p>Thanks for reading 👍</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d10d94b1e680" width="1" height="1" alt=""><hr><p><a href="https://tech.new-work.se/using-docker-for-running-android-tests-on-your-ci-d10d94b1e680">Using Docker for running Android Tests on your CI</a> was originally published in <a href="https://tech.new-work.se/">New Work Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Multi module navigation with the Android Architecture component]]></title>
            <link>https://medium.com/@hartwich.daniel/multi-module-navigation-with-the-android-architecture-component-82ed028fa1d9?source=rss-afc3af7716b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/82ed028fa1d9</guid>
            <category><![CDATA[architecture-components]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[modularization]]></category>
            <dc:creator><![CDATA[Daniel Hartwich]]></dc:creator>
            <pubDate>Thu, 28 Jun 2018 08:15:11 GMT</pubDate>
            <atom:updated>2018-09-21T01:14:21.184Z</atom:updated>
            <content:encoded><![CDATA[<p>There are already plenty of articles about the new <a href="https://developer.android.com/topic/libraries/architecture/navigation/">Navigation Architecture Component</a>. It sounds awesome and I wanted to use it in one of my side projects.</p><p>The project I am working on has multiple modules that need to be able to navigate between each other which is where my problem started.</p><p>Of course you could have your :app module depend on all of the feature modules and just handle the navigation within a single navigation resource file. However, thinking about bigger apps, this can become a problem really quickly. Just imagine an app that has 20 or 30 screens, how are we going to keep an overview of the screens, what is connected with what and many other problems.</p><p>It seems natural, that we want to seperate the navigation to its feature modules. When searching for a solution I couldn’t find anything that helped me to understand the problem.</p><p>But then I found this tweet:</p><h3>Ian Lake on Twitter</h3><p>@yahyabayramoglu @keyboardsurfer You can &amp;lt;include app:graph=&quot;@navigation/module_graph&quot;/&amp;gt; to bring in graphs from other modules and &amp;lt;activity&amp;gt; destinations make linking between Instant App features possible. An Instant app+Navigation sample and docs around that exact use case are already on our todo list!</p><p>🤔 Seems interesting, right?</p><p>So theoretically, we can create multiple navigation graph files (one per feature module) which only represent the module internal navigation. The navigation between the modules themselves can happen by including the graphs of the feature module to the entry point of the parent module.</p><h3><strong>Wait… What?</strong></h3><p>Yea, I get it… it sounds overly complicated and it shouldn’t be. It actually isn’t.</p><p>Enough talk, let’s spin up an example.</p><p>Imagine a beautiful project with three modules for now. The main app module called <strong><em>:app</em></strong> and two feature modules called <strong><em>:first_feature</em></strong> and <strong><em>:second_feature</em></strong>.</p><p>From <strong><em>:app</em></strong> you can navigate to <strong><em>:first_feature</em></strong>, from <strong><em>:first_feature</em></strong> you can navigate to <strong><em>:second_feature</em></strong> and inside <strong><em>:second_feature</em></strong> you have multiple screens that you want to navigate to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*7DSxFB48PAQ9rMSRlIWlZg.png" /><figcaption>Structure of our simple app</figcaption></figure><p>So, how should our graph looks like?</p><p>In our :app module’s navigation_graph.xml we need to include the graphs of our features. Just do it inside the <em>&lt;navigation&gt;</em> tag.</p><pre>    &lt;<strong>include </strong>app:graph=&quot;@navigation/first_feature_graph&quot; /&gt;</pre><pre>    &lt;<strong>include </strong>app:graph=&quot;@navigation/second_feature_graph&quot; /&gt;</pre><p>Now our navigation_graph.xml in the :app module should look similar to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*Qh5oIc7u44Kj6k8zr9Ln1A.png" /><figcaption>navigation_graph.xml after adding the dependency to the two feature graphs</figcaption></figure><p>In our :second_feature navigation_graph.xml we just add the internal fragments for navigation following the turorials we can find everywhere.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*ZgNu4SV698YEWms_Y5MhuA.png" /><figcaption>:second_feature navigation graph</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b24ae5e11d28eba3885200f360600dfb/href">https://medium.com/media/b24ae5e11d28eba3885200f360600dfb/href</a></iframe><h3><strong>And that’s it ✅</strong></h3><p>With this little “trick” we can separate our navigation graphs from each other and still access them.</p><p>Unfortunately it is not possible to access the graphs of other modules without depending on them.</p><p>If you are interested in checking out an example feel free to take a look at my sample GitHub repository:</p><p><a href="https://github.com/dhartwich1991/android-multi-module-navigation">dhartwich1991/android-multi-module-navigation</a></p><p>Thank you very much for reading :)</p><p>If you have any feedback, questions or comments don’t hesitate to ping me on <a href="https://twitter.com/killya_">Twitter(@KiLLyA_)</a> or in the comments below. 👍</p><p><strong>This story is published in </strong><a href="http://blog.usejournal.com/"><strong>Noteworthy</strong></a><strong>, where 10,000+ readers come every day to learn about the people &amp; ideas shaping the products we love.</strong></p><p><a href="http://blog.usejournal.com/"><strong>Follow our publication</strong></a><strong> to see more product &amp; design stories featured by the </strong><a href="https://usejournal.com/?/utm_source=usejournal.com&amp;utm_medium=blog&amp;utm_campaign=guest_post&amp;utm_content=brad_armstong"><strong>Journal</strong></a><strong> team.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82ed028fa1d9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>