<?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 Oren Aviad on Medium]]></title>
        <description><![CDATA[Stories by Oren Aviad on Medium]]></description>
        <link>https://medium.com/@orenaviad?source=rss-9eda1ff4f9cc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*VFLfsTZ6YtgkVuwQDTDFyQ.png</url>
            <title>Stories by Oren Aviad on Medium</title>
            <link>https://medium.com/@orenaviad?source=rss-9eda1ff4f9cc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 10:14:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@orenaviad/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[A Deep Dive into Android Espresso]]></title>
            <link>https://medium.com/att-israel/a-deep-dive-into-android-espresso-3feed15d204c?source=rss-9eda1ff4f9cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/3feed15d204c</guid>
            <category><![CDATA[junit]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Oren Aviad]]></dc:creator>
            <pubDate>Thu, 23 Jul 2020 08:53:09 GMT</pubDate>
            <atom:updated>2020-07-23T08:53:09.391Z</atom:updated>
            <content:encoded><![CDATA[<h4>A step by step guide on how to write automation tests with Espresso framework</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zWfhglB1AldoC3Kl" /><figcaption>Photo by <a href="https://unsplash.com/@an_ku_sh?utm_source=medium&amp;utm_medium=referral">Ankush Minda</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>To be honest, I’ve never been such a big fan of automation testing. In every company I’ve worked for in the last 15 years, implementation of the automation testing process has always failed. <strong>However, things have changed dramatically…</strong></p><p>In the past, development and QA were two isolated processes running in sequential phases. With the advent of <a href="https://www.scaledagileframework.com/built-in-quality/"><strong>Built-in Quality</strong></a> practices and <strong>Agile</strong>, <strong>DevOps </strong>and<strong> Shift Left </strong>approaches, this scenario has completely changed.</p><p>Today, development is closely tied to testing. On one hand, developers are being incorporated into the testing cycle earlier than ever before. On the other hand, QA testers have to adapt quickly and learn development skills.</p><p>In line with these new practices and approaches, today we have an extensive ecosystem of automation tools, CI systems and testing frameworks. Google’s <strong>Espresso</strong> testing framework is one of them.</p><h3>What is the Espresso Framework?</h3><blockquote>The Espresso testing framework provides a set of APIs to build UI tests to test user flows within an app. These APIs let you write automated UI tests that are concise and that run reliably. Espresso is well-suited for writing white box-style automated tests, where the test code utilizes implementation code details from the app under test.</blockquote><h4>The main components of Espresso:</h4><ul><li><strong>Espresso</strong> : Entry point to interactions with views (via onView() and onData()). Also exposes APIs that are not necessarily tied to any view, such as pressBack().</li><li><strong>ViewMatchers:</strong> allows you to find a view in the current view hierarchy.</li><li><strong>ViewActions: </strong>allows you to perform actions on the views.</li><li><strong>ViewAssertions: </strong>allows you to assert the view state.</li></ul><h3>Espresso vs. Appium</h3><p>Below are the key differences between the two popular test automation frameworks for mobile app testing: <strong>Appium</strong> and <strong>Espresso.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*t8D7PAFpnA3ENW9aCVeoAw.png" /></figure><h3>Espresso setup instructions</h3><h4>Add Espresso dependencies</h4><p>In your app’s top-level build.gradle file, you need to specify these libraries as dependencies:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/253a3b2f1fc7f0d5bcd28a8da7b154f6/href">https://medium.com/media/253a3b2f1fc7f0d5bcd28a8da7b154f6/href</a></iframe><h4>Set the instrumentation runner</h4><pre>testInstrumentationRunner &quot;androidx.test.runner.AndroidJUnitRunner&quot;</pre><h3>Location of Espresso Tests</h3><p>In your Android Studio project, you must store the source files for espresso tests at module-name/src/androidTest/java/. This directory already exists when you create a new project that contains an example instrumented test.</p><h3>JUnit 5 support</h3><p>Currently, there is no support for JUnit5. :(</p><h3>Espresso Test Recorder</h3><blockquote><em>The Espresso Test Recorder tool lets you create UI tests for your app without writing test code. By recording a test scenario, you can record your interactions with a device and add assertions to verify UI elements in particular snapshots of your app. Espresso Test Recorder then takes the saved recording and automatically generates a corresponding UI test that you can run to test your app</em></blockquote><p>To start recording a test with Espresso Test Recorder:</p><ol><li>Click <strong>Run </strong>&gt;<strong> Record Espresso Test</strong>.</li><li>In the <strong>Select Deployment Target</strong> window, choose the device on which you want to record the test. Click <strong>OK</strong>.</li><li>Espresso Test Recorder triggers a build of your project, and the app must install and launch before Espresso Test Recorder allows you to interact with it. The <strong>Record Your Test</strong> window appears after the app launches. Interact with your device to start logging events such as “tap” and “type” actions.</li><li>To save a recording, click <strong>OK.</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*J5P2clF5pYbLUbWG9Ap9HA.png" /></figure><h3>Let’s write some Espresso tests!</h3><p>In our sample app (see below)<strong>, </strong>we would like to validate the LoginActivity screen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*5KAx2hUkMbdbk6Ho-VNqWQ.png" /></figure><p>Let’s write a simple example on how to validate the scenario when a user enters valid/invalid credentials:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00f2f2b93d0a106346d4c7c9af978de6/href">https://medium.com/media/00f2f2b93d0a106346d4c7c9af978de6/href</a></iframe><p>Here, we use the <a href="https://developer.android.com/reference/androidx/test/ext/junit/rules/ActivityScenarioRule">ActivityScenarioRule</a>, which launches a given activity before the test starts and closes after the test. You can access the <a href="https://developer.android.com/reference/androidx/test/core/app/ActivityScenario">ActivityScenario</a> via the <a href="https://developer.android.com/reference/androidx/test/ext/junit/rules/ActivityScenarioRule#getScenario()">getScenario()</a> method, which allows you to run an action on the current activity, launch an activity and more. This rule is an upgraded version of <a href="https://developer.android.com/reference/androidx/test/rule/ActivityTestRule">ActivityTestRule</a>. The previous version will be deprecated and eventually be removed from the library in the future.</p><p>When the user enters valid credentials, we validate that the login<strong> </strong>button is enabled, and the welcome string contains the user name entered. However, when the user enters invalid credentials, we validate that the login<strong> </strong>button is disabled, and an error popup is displayed with the correct error message.</p><p>Now, let’s write a more advanced example: how to validate that clicking on the login<strong> </strong>button is sending the correct <a href="https://developer.android.com/reference/android/content/Intent">Intent</a>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4af23d77ce737598079cb98fc0d43295/href">https://medium.com/media/4af23d77ce737598079cb98fc0d43295/href</a></iframe><p>Here, we use the <a href="https://developer.android.com/reference/androidx/test/espresso/intent/rule/IntentsTestRule"><strong>IntentsActivityRule</strong></a><strong>, </strong>which initializes Espresso-Intents before each test and releases Espresso-Intents after each test run.</p><p>When the user enters valid credentials and clicks the login button, we validate that a new Intent was sent with the MainActivity component and with an extra named “displayName” containing the user name entered.</p><h4>What if we wanted to do some setup in our Activity before launching it?</h4><p>With the current version of <a href="https://developer.android.com/reference/androidx/test/ext/junit/rules/ActivityScenarioRule.html">ActivityScenarioRule</a> we aren’t able to do this.<a href="https://developer.android.com/reference/androidx/test/ext/junit/rules/ActivityScenarioRule.html">ActivityScenarioRule</a> launches the Activity before we can get to our test method where we would actually like to do the setup, e.g. set some Intent extras.</p><p>For this, we need to use <a href="https://developer.android.com/reference/androidx/test/core/app/ActivityScenario.html">ActivityScenario</a> directly and remember to clean up afterwards, e.g. in an @After annotated method or with the help of a try-with-resources block. See the example below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/89198e5d2d7f4747b8b09da150dea0c5/href">https://medium.com/media/89198e5d2d7f4747b8b09da150dea0c5/href</a></iframe><p>Here, we are launching the MainActivity only after we setup the Intent with a long display name.</p><p>That’s all! I hope you liked this article. <strong>Happy testing</strong>!</p><p>Extra articles and resources to look at:</p><ol><li>Source code for the <strong>sample app</strong> in this article is available at: <a href="https://github.com/oaviad/espressoClub">https://github.com/oaviad/espressoClub</a></li><li><a href="https://developer.android.com/training/testing/espresso/cheat-sheet">Espresso Cheat Sheet</a></li><li><a href="https://developer.android.com/training/testing/espresso/basics">Espresso Basics</a></li><li><a href="https://developer.android.com/studio/test/espresso-test-recorder">Espresso Test Recorder</a></li><li><a href="https://medium.com/att-israel/double-espresso-728285a9057e">Double Espresso Anyone? ☕️</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3feed15d204c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/att-israel/a-deep-dive-into-android-espresso-3feed15d204c">A Deep Dive into Android Espresso</a> was originally published in <a href="https://medium.com/att-israel">AT&amp;T Israel Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ REFACTORISM ]]></title>
            <link>https://medium.com/att-israel/refactorism-937b5371e3c8?source=rss-9eda1ff4f9cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/937b5371e3c8</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[code-refactoring]]></category>
            <dc:creator><![CDATA[Oren Aviad]]></dc:creator>
            <pubDate>Wed, 10 Jun 2020 13:40:16 GMT</pubDate>
            <atom:updated>2022-09-22T12:48:38.598Z</atom:updated>
            <content:encoded><![CDATA[<h4>THE SECRET RELIGION OF THE DEVELOPERS</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2xDNl7BfzwTrBV5C3xb6LA.jpeg" /><figcaption>Photo on <a href="https://aleteia.org/">aleteia.org</a></figcaption></figure><blockquote><em>Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code, yet improves its internal structure.</em></blockquote><blockquote><em>— Martin Fowler</em></blockquote><p>As far as I remember, I considered myself as a <strong><em>refactorian</em></strong> (a developer who believes in <strong><em>refactorism</em></strong>). Actually, it took me several years to get here. I arrived after hours and days of refactoring legacy code, refactoring workshops and pair programming with some of the best <strong><em>refactorians</em></strong> I had had the pleasure of working with. I finally left behind my annoying fear of <strong>“it’s gonna blow”</strong> that every developer feels when starting to refactor.</p><p>The excitement of transforming spaghetti code into clean code without changing its functionality, playing with all the moving parts all together until everything fits in like magic, is something that always motivated me. I won’t lie to you — refactoring is hard work, however, it’s definitely pays off.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QgfpJjO0KUzn8ot_" /><figcaption>Photo by <a href="https://unsplash.com/@cristian1?utm_source=medium&amp;utm_medium=referral">Cristian Escobar</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>If It Ain’t Broke, Don’t Fix It.</blockquote><blockquote>— Anonymous Loser 😜</blockquote><h3>When do you need to refactor your code?</h3><h4>Rule #1:</h4><blockquote>You don’t decide to refactor, you refactor because you want to do something else and refactoring helps you to do it.</blockquote><h4>Rule #2:</h4><blockquote>The first time you do something, you just do it. The second time you do something similar, you wince at the duplication, but you do the duplicate thing anyway. The third time you do something similar, you refactor.</blockquote><blockquote>— Don Roberts</blockquote><h3>Why is refactoring important?</h3><ul><li>Makes code more readable, easier to understand</li><li>Cleans up code and makes it tidier</li><li>Makes code more maintainable</li><li>Makes it easier to add new features</li><li>Removes redundant, unused code and comments</li><li>Improves performance</li><li>Makes code more generic</li><li>Keeps code DRY (Don’t Repeat Yourself)</li><li>Creates reusable code</li><li>Better class and function cohesion</li><li>Makes your code testable</li></ul><h3>Some Tips before you start…</h3><ol><li>Do it gradually!.</li><li>Always start from green ✅ (test passing) and end in green ✅. Otherwise, you’re not refactoring.</li><li>If it’s not going well, take a deep breath, roll back your changes and start over.</li></ol><p>Now, if you are a true believer 🙏, start refactoring and happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=937b5371e3c8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/att-israel/refactorism-937b5371e3c8">🙌 REFACTORISM 🙌</a> was originally published in <a href="https://medium.com/att-israel">AT&amp;T Israel Tech Blog</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 Migrate to Encrypted Shared Preferences]]></title>
            <link>https://medium.com/att-israel/how-to-migrate-to-encrypted-shared-preferences-cc4105c03518?source=rss-9eda1ff4f9cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc4105c03518</guid>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[sharedpreferences]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Oren Aviad]]></dc:creator>
            <pubDate>Mon, 04 May 2020 10:51:41 GMT</pubDate>
            <atom:updated>2020-06-22T13:16:10.902Z</atom:updated>
            <content:encoded><![CDATA[<h4>THE SECRET GUIDE</h4><h4>A step by step guide on how to migrate to encrypted shared preferences</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OMOMHleka0UxSI5k" /><figcaption>Photo by <a href="https://unsplash.com/@josenothose?utm_source=medium&amp;utm_medium=referral">Jose Fontano</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The Android framework provides us with <a href="https://developer.android.com/training/data-storage/shared-preferences">SharedPreferences</a>, which is a great way to store a small collection of key-value data. When working with sensitive data, however, it’s important to understand that SharedPreferences stores data as plain text. We should encrypt sensitive data to prevent it from being hacked. How can we do so?</p><p>The <a href="https://developer.android.com/topic/security/data">Security</a> library comes to the rescue!</p><blockquote>The Security library, part of <a href="https://developer.android.com/jetpack">Android Jetpack</a>, provides an implementation of the <a href="https://developer.android.com/topic/security/best-practices">security best practices</a> related to reading and writing data, as well as key creation and verification.</blockquote><p>In this article, I’ll share with you how to migrate your existing Shared Preferences<strong> </strong>to<strong> </strong><a href="https://developer.android.com/reference/androidx/security/crypto/EncryptedSharedPreferences">EncryptedSharedPreferences</a>. Stay tuned:)</p><h3>Setup</h3><p>To get started with the AndroidX Security library, add the following dependency to your module-level build.gradle file.</p><pre>dependencies {<br>    implementation &quot;androidx.security:security-crypto:1.0.0-rc01&quot;<br>}</pre><p>In order to use this library, you will need to set <strong>minSdkVersion</strong> to 23+</p><pre>android {</pre><pre> defaultConfig {<br>    <strong>minSdkVersion 23</strong><br> }<br>}</pre><p>However, in case your application is targeting devices below minSdkVersion 23, do not apply this change and add the following line to your AndroidManifest.xml:</p><pre>&lt;uses-sdk tools:overrideLibrary=&quot;androidx.security&quot;/&gt;</pre><h3>Coding-Time!</h3><h4>SharedPreferencesManager</h4><p>Interface with all the SharedPreferences APIs supported.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc0b345b2affa30bb266e30a8b3edd4d/href">https://medium.com/media/fc0b345b2affa30bb266e30a8b3edd4d/href</a></iframe><h4>SharedPreferencesManagerImpl</h4><p>Handling the creation of the EncryptedSharedPreferences in case SDK version is ≥ 23, otherwise we will keep using the original non-encrypted SharedPreferences.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/201a39115675f5e14c62f1ba29f5be23/href">https://medium.com/media/201a39115675f5e14c62f1ba29f5be23/href</a></iframe><h4>SharedPreferencesUtils</h4><p>These methods in SharedPreferencesUtils class, extend the SharedPreferences class to give more abilities.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8185173cc78bc9cef110a2d448e36b00/href">https://medium.com/media/8185173cc78bc9cef110a2d448e36b00/href</a></iframe><h3>Summary</h3><p>Android’s SharedPreferences is a useful tool to store key-value data and when that data is sensitive, it’s a good idea to encrypt it. The recent AndroidX Security library is a welcome addition that provides us with a simple and easy-to-use interface to do so.</p><p>That’s all! I hope you liked this article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc4105c03518" width="1" height="1" alt=""><hr><p><a href="https://medium.com/att-israel/how-to-migrate-to-encrypted-shared-preferences-cc4105c03518">How to Migrate to Encrypted Shared Preferences</a> was originally published in <a href="https://medium.com/att-israel">AT&amp;T Israel Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Double Espresso Anyone? ☕️]]></title>
            <link>https://medium.com/att-israel/double-espresso-728285a9057e?source=rss-9eda1ff4f9cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/728285a9057e</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[espresso-testing]]></category>
            <dc:creator><![CDATA[Oren Aviad]]></dc:creator>
            <pubDate>Tue, 21 Apr 2020 13:05:06 GMT</pubDate>
            <atom:updated>2020-04-27T19:50:35.363Z</atom:updated>
            <content:encoded><![CDATA[<h4>Espresso Framework - Some Additional Info You Probably Missed</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Q8BT8qnb-twI3r37" /><figcaption>Photo by <a href="https://unsplash.com/@relentlessjpg?utm_source=medium&amp;utm_medium=referral">William Moreland</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><ol><li>Overview</li><li>Android Test Orchestrator</li><li>Espresso Test Recorder</li><li>ActivityScenarioRule</li><li>How to get current Activity</li><li>Combine UIAutomator &amp; Espresso tests</li><li>Error: “<em>Action will not be performed because the target view does not match one or more of the following constraints: at least 90 percent of the view’s area is displayed to the user</em>”</li></ol><h3>Overview</h3><p>Testing user interactions within your app ensures that users do not encounter unexpected results or have a poor experience when interacting with your app. If you are an Android developer, Espresso Framework is definitely the right tool for it.</p><blockquote>Espresso is targeted at developers who believe that automated testing is an integral part of the development lifecycle. While it can be used for black-box testing, Espresso’s full power is unlocked by those who are familiar with the codebase under test.</blockquote><p>In this article, I’ll share with you some useful info I’ve encountered while working with Espresso Framework.</p><h3><strong>Android Test Orchestrator</strong></h3><blockquote>Android Test Orchestrator allows you to run each of your app’s tests within its own invocation of <a href="https://developer.android.com/reference/android/app/Instrumentation">Instrumentation</a></blockquote><h4><strong>What issues does it solve?</strong></h4><ul><li><strong>Minimal shared state </strong>- each test runs in its own Instrumentation instance</li><li><strong>Crashes isolation </strong>-<strong> </strong>even if one test crashes, it takes down only its own instance of Instrumentation, so the other tests in your suite still run</li></ul><p>To enable from Gradle, you should add the following statements to your project’s <strong>build.gradle</strong> file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21c538e5c210635e6a68b84d63175bf6/href">https://medium.com/media/21c538e5c210635e6a68b84d63175bf6/href</a></iframe><h3>Espresso Test Recorder</h3><blockquote>The Espresso Test Recorder tool lets you create UI tests for your app without writing any test code. By recording a test scenario, you can record your interactions with a device and add assertions to verify UI elements in particular snapshots of your app. Espresso Test Recorder then takes the saved recording and automatically generates a corresponding UI test that you can run to test your app</blockquote><h4>How to configure Espresso Test Recorder</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D8RdIosM7hu6A-2orxocHA.png" /><figcaption>Android Studio Preferences -&gt; Espresso Test Recorder</figcaption></figure><ul><li>You might want to lower <strong>Assertion depth </strong>to<strong> 1</strong>.<strong> </strong>This way, the added assertions will not rely on child positions to identify the asserted elements and result in much simpler assertions</li><li>You might want to uncheck <strong>Clear app data before/after recording</strong>. This way, your app state will not be cleared before/after each recording</li></ul><p>To learn more about <strong>Espresso Test Recorder</strong>, you can read <a href="https://developer.android.com/studio/test/espresso-test-recorder">here</a>.</p><h3>ActivityScenarioRule</h3><blockquote>This rule is an upgraded version of <a href="https://developer.android.com/reference/androidx/test/rule/ActivityTestRule">ActivityTestRule</a>. The previous version will be deprecated and eventually removed from the library in the future.</blockquote><pre>Example:</pre><pre>@get:Rule<br>val rule = activityScenarioRule&lt;MyActivity&gt;()</pre><pre>@Test <br>void myTest() {<br>  val scenario = rule.getScenario();  <br>  // Your test code goes here.<br>}</pre><h3>How to get current Activity</h3><p>Sometimes when writing a test you need to know what the current activity is being used. In case you are in the activity under test, you can use the following:</p><pre>@Test <br>void myTest() {<br>  val scenario = rule.getScenario();<br>  scenario.onActivity { activity -&gt;      <br>     // do some stuff with the Activity<br>  }<br>}</pre><p>However, in case you aren’t, you should use the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ee46925c98441f096e09871a01515ea/href">https://medium.com/media/0ee46925c98441f096e09871a01515ea/href</a></iframe><h3>Combine UIAutomator &amp; Espresso tests</h3><p>While <strong>Espresso</strong> framework allows you to test many things <em>inside</em> your application in a simple way, <strong>UIAutomator</strong> is an automation framework for testing <em>outside</em> of your application, which allows you to perform actions such as:</p><ul><li>Change the device rotation</li><li>Press a hardware key, such as “volume up”</li><li>Press the Back, Home, or Menu buttons</li><li>Open the notification shade</li><li>Take a screenshot of the current window</li></ul><p>Fortunately, we can combine these two frameworks in a test.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/29444186d95bb227384ce3c260923e12/href">https://medium.com/media/29444186d95bb227384ce3c260923e12/href</a></iframe><h3>Error: “<em>Action will not be performed because the target view does not match one or more of the following constraints: at least 90 percent of the view’s area is displayed to the user</em>”</h3><p>In case you got this error, it is because the view you are trying to perform an action on is not fully displayed. To solve it, you should use a <strong>custom</strong> <strong>ViewAction</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9183a5f64c50b87774894de0da6e257d/href">https://medium.com/media/9183a5f64c50b87774894de0da6e257d/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F7250101&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fespresso-classy-pinkies-up-sips-tea-sipping-gif-7250101&amp;image=https%3A%2F%2Fmedia.tenor.com%2Fimages%2Fab1aef57306ec92600cd28672b055895%2Ftenor.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8a77e67421ee927f7aa624803a43e6b/href">https://medium.com/media/b8a77e67421ee927f7aa624803a43e6b/href</a></iframe><p>~ Thanks for reading ~</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=728285a9057e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/att-israel/double-espresso-728285a9057e">Double Espresso Anyone? ☕️</a> was originally published in <a href="https://medium.com/att-israel">AT&amp;T Israel Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modernize Your Android Legacy App]]></title>
            <link>https://medium.com/att-israel/modernize-your-android-legacy-app-b78d74aab640?source=rss-9eda1ff4f9cc------2</link>
            <guid isPermaLink="false">https://medium.com/p/b78d74aab640</guid>
            <category><![CDATA[modern]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[legacy]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Oren Aviad]]></dc:creator>
            <pubDate>Thu, 12 Mar 2020 13:47:53 GMT</pubDate>
            <atom:updated>2020-05-03T10:59:34.284Z</atom:updated>
            <content:encoded><![CDATA[<h4>A step by step guide on how to modernize your legacy app</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zrGXnwXce8w7qpLX" /><figcaption>Photo by <a href="https://unsplash.com/@vanveenjf?utm_source=medium&amp;utm_medium=referral">VanveenJF</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>One of the biggest dilemmas when deciding to modernize a legacy app is wondering exactly why you have to do it. I won’t lie. It requires a significant amount of refactoring and hard work.</p><p>So what exactly is a <strong><em>modern</em></strong> app? a modern app is one that uses the newest best coding practices along with the recommended architecture.</p><p>In this article, I’ll share with you the <strong>why</strong> and <strong>how.</strong> Stay tuned:)</p><h3><strong>Why modernize your legacy App?</strong></h3><ul><li>Gain more <strong>Performance</strong> for your application</li><li>Speed up your application <strong>Delivery</strong></li><li>Leverage your application <strong>Security</strong></li><li>Improve your application <strong>Compatibility</strong></li><li>Improve your application <strong>Stability</strong></li></ul><h3>Let’s get started</h3><h4>Some Tips</h4><ol><li>Do it gradually!</li><li>Make sure your new code does not break your existing tests.</li><li>Measure how your changes affects the application.</li></ol><h3>Step #1 - Migrate to Kotlin</h3><h4>Why migrate to Kotlin from Java?</h4><ul><li>Google’s recommendation</li><li><strong>Null Safety</strong> leaves the <a href="https://medium.com/@hinchman_amanda/null-pointer-references-the-billion-dollar-mistake-1e616534d485"><strong>1 billion dollar mistake</strong></a> behind you.</li><li>Using Kotlin you can write approx 40% less lines of code compared to Java and as you know: <strong>less code = less bugs = less coding time.</strong></li><li>Write async code in a sequential manner using <strong>Coroutines.</strong></li></ul><p>To learn more about it, you can read the following article:</p><p><a href="https://medium.com/@laurenyew/why-migrate-your-android-app-to-kotlin-2220218952a9">Why migrate your Android app to Kotlin?</a></p><p>In the following example, you can see how to simplify code that executes asynchronously:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8480a2c1e426389935d7707bc82bb6c/href">https://medium.com/media/a8480a2c1e426389935d7707bc82bb6c/href</a></iframe><p>It’s simple, using Retrofit library — a type-safe HTTP client &amp; Coroutines we are sending a request to server to get our Inbox response which is an async call and then return a response or an exception in case of failure.</p><h3>Step #2 - Start using Android Jetpack</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f3Xiva3e2VoPVsJEPY5NDg.png" /><figcaption><a href="https://www.cleveroad.com/">https://www.cleveroad.com</a></figcaption></figure><blockquote>Jetpack is a suite of libraries, tools, and guidance to help developers write high-quality apps easier. These components help you follow best practices, free you from writing boilerplate code, and simplify complex tasks, so you can focus on the code you care about.</blockquote><p>To enjoy the jetpack goodies, you first have to migrate your application to <strong>AndroidX</strong>.</p><h4>AndroidX</h4><ul><li>Jetpack comprises the <strong>androidx.*</strong> package libraries</li><li>Support library version 28.0.0 is the last release of the support library</li><li><strong>AndroidX</strong> artifacts with version 1.0.0 are binary equivalent to the support library 28.0.0 artifacts.</li></ul><h4>Migrate to AndroidX</h4><p>With Android Studio 3.2 and higher, you can migrate an existing project to <strong>AndroidX</strong> by selecting <strong>Refactor &gt; Migrate to AndroidX</strong> from the menu bar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wewKLaOAZcEwn6k7yHICWQ.jpeg" /></figure><p>To learn more about it you can read <a href="https://developer.android.com/jetpack/androidx/migrate">here</a>.</p><h3>Architecture Components</h3><blockquote>Android architecture components are a collection of libraries that help you design robust, testable, and maintainable apps.</blockquote><h4>ViewModel</h4><ul><li>Helper class for the UI controller responsible for preparing data for the UI</li><li>Automatically retained during configuration changes</li><li>Scoped to a lifecycle</li></ul><h4>LiveData</h4><blockquote>LiveData is an observable data holder class.</blockquote><p>LiveData is lifecycle-aware and it has the following advantages:</p><ul><li>Auto handling of lifecycle-related stuff</li><li>Avoids memory leaks</li><li>Avoids stupid crashes</li><li>Always up to date data</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*kSt-3Fh3V8rPuRioxjwmTg.png" /><figcaption><strong>LiveData &amp; ViewModel flow</strong></figcaption></figure><p>In the following example, you can see how to implement MVVM architecture using <strong>LiveData</strong> &amp; <strong>ViewModel</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f11aa4e02e8e1a592d7cd1d68b62be2/href">https://medium.com/media/8f11aa4e02e8e1a592d7cd1d68b62be2/href</a></iframe><blockquote><strong>Loaders</strong> have been deprecated as of Android P (API 28). The recommended option for dealing with loading data while handling the Activity and Fragment lifecycles is to use a combination of <a href="https://developer.android.com/reference/androidx/lifecycle/ViewModel"><strong>ViewModels</strong></a> and <a href="https://developer.android.com/reference/androidx/lifecycle/LiveData"><strong>LiveData</strong></a>.</blockquote><h4>Room</h4><blockquote>Room provides an abstraction layer over SQLite to allow fluent database access while harnessing the full power of SQLite.</blockquote><p>There are 3 major components in Room:</p><ul><li><strong>Database: </strong>database holder</li><li><strong>Entity: </strong>a class<strong> </strong>represents<strong> </strong>a table within the database</li><li><strong>Dao: </strong>contains the methods used for accessing the database</li></ul><h4>Why migrate to Room?</h4><ul><li>Integration with LiveData to always be updated</li><li>Better performance and internal caching</li><li>Easy to write instrumentation tests using Room.inMemoryDatabaseBuilder()</li></ul><p>In the following example, you can see how to create the <strong>Room</strong> components:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9870b20c2409671f7f53987acc8d427c/href">https://medium.com/media/9870b20c2409671f7f53987acc8d427c/href</a></iframe><p>To learn more about <strong>Android</strong> <strong>Jetpack</strong>, you can read <a href="https://developer.android.com/jetpack">here</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F5531028&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fwill-ferrell-old-school-gif-5531028&amp;image=https%3A%2F%2Fmedia.tenor.com%2Fimages%2Fbf3bfff06faee3f5cb9f6eff6ef91748%2Fraw&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/402258082637e4b1a0f4ac37fb40ebb1/href">https://medium.com/media/402258082637e4b1a0f4ac37fb40ebb1/href</a></iframe><h3>Step #3 - Migrate to Junit5</h3><h4>What’s New?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*OZrCXJ7ujxWERggp1Sn3fQ.png" /><figcaption><a href="https://www.luxoft-training.com/">www.luxoft-training.com</a></figcaption></figure><h4>Extension Model</h4><ul><li>Extends the behavior of test classes or methods (lifecycle)</li><li>Replaces <strong>JUnit runner</strong> and <strong>Junit Rules</strong></li><li>Supports multiple extensions</li></ul><h4>New @TestInstance mode: Lifecycle.PER_CLASS</h4><p>Creates only one instance of the test class and reuse it between tests.</p><p>In the following example, you can see how to write Unit Test for our <strong>InboxViewModel</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae23352bca0efebeee6e3aa21feffae3/href">https://medium.com/media/ae23352bca0efebeee6e3aa21feffae3/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*BJixuCptKBi7mhqzcG72og.png" /></figure><p>Now, have we finished our work? Hmmm… the answer is No! We live in a dynamic environment where everything can change and evolve, which is a good thing. We will always need to be updated with the newest best practices in the Android world and keep modifying our apps with new changes.</p><p>That’s all! I hope you liked this article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b78d74aab640" width="1" height="1" alt=""><hr><p><a href="https://medium.com/att-israel/modernize-your-android-legacy-app-b78d74aab640">Modernize Your Android Legacy App</a> was originally published in <a href="https://medium.com/att-israel">AT&amp;T Israel Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>