<?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 Mark Difranco on Medium]]></title>
        <description><![CDATA[Stories by Mark Difranco on Medium]]></description>
        <link>https://medium.com/@mark.difranco?source=rss-f41ce1f58397------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*nbarr2dQnEUSJvT3</url>
            <title>Stories by Mark Difranco on Medium</title>
            <link>https://medium.com/@mark.difranco?source=rss-f41ce1f58397------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 09:47:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mark.difranco/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[Faire Tech Talk: scaling mobile foundation]]></title>
            <link>https://craft.faire.com/faire-tech-talk-scaling-mobile-foundation-147093d1afcb?source=rss-f41ce1f58397------2</link>
            <guid isPermaLink="false">https://medium.com/p/147093d1afcb</guid>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[engineering]]></category>
            <dc:creator><![CDATA[Mark Difranco]]></dc:creator>
            <pubDate>Wed, 11 May 2022 15:44:14 GMT</pubDate>
            <atom:updated>2022-05-17T21:28:17.691Z</atom:updated>
            <content:encoded><![CDATA[<h3>Faire Tech Talk: Scaling mobile foundation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n7ofL0a3anIOUclYxO1Vvw.jpeg" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplayer.vimeo.com%2Fvideo%2F708690466%3Fh%3D60d86e084a%26app_id%3D122963&amp;dntp=1&amp;display_name=Vimeo&amp;url=https%3A%2F%2Fvimeo.com%2F708690466&amp;image=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F1429898459-2c189e2836e0d19b5b7eca0408b836c3f96eada77898c55120c5a4c58413319f-d_1280&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=vimeo" width="1920" height="1080" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ebcab1d7be9640a5e9bb2519ea0244b/href">https://medium.com/media/2ebcab1d7be9640a5e9bb2519ea0244b/href</a></iframe><p><strong>About The Talk</strong></p><p>At <a href="https://www.linkedin.com/company/18013280/admin/#">Faire</a>, we launched our customer Retailer app over 3 years ago. Although many of the architectural decisions we made back then have survived the test of time, some have limited our ability to scale.</p><p>Recently, we took a holistic look at our architecture, retired parts that were no longer serving our needs, and adopted some new tools. We also tried to align strategies across both platforms.</p><p>In the latest Faire Tech Talk, Engineers <a href="https://www.linkedin.com/company/18013280/admin/#">Mark DiFranco</a> and <a href="https://www.linkedin.com/company/18013280/admin/#">Udey Rishi</a> walk us through the journey of building and scaling Faire’s Retailer app, and the latest updates we’ve made to continue to provide our customers with an exceptional experience.</p><p><strong>About The Speaker:</strong> <a href="https://www.linkedin.com/in/mpdifranco/">Mark DiFranco</a></p><p>Mark is a Staff iOS Engineer who joined Faire in 2019. He founded the iOS team and had the opportunity to build the Retailer app from the ground up. Since then, he’s been responsible for scaling the iOS team up to over 20 engineers and now works on the Mobile Platform team.</p><p><strong>About The Speaker:</strong> <a href="https://www.linkedin.com/in/udeyrishi/">Udey Rishi</a></p><p>Udey is an Android Staff Engineer who joined Faire in 2021. Since joining Faire, he has worked on some important user-facing features on the Retailer app. But his primary focus has been to identify ways to scale our mobile stack for our growing headcount and feature delivery speeds. He is now working on the Mobile Platform team to execute that goal. Prior to joining Faire, he built and shipped multiple Android and React Native apps with millions of active users.</p><p>Faire’s Mobile Engineering Team is hiring — join us! <a href="https://www.faire.com/careers?utm_source=blog&amp;utm_medium=blog&amp;utm_campaign=craft&amp;utm_content=article_5_11-22">www.faire.com/careers</a></p><p><strong>Interested in learning more about what Faire’s Mobile Team is building?</strong> Check out these other Faire Tech Talks:</p><p><a href="https://craft.faire.com/mobile-internationalization-at-faire-2c70fbd3432b">Mobile Internationalization at Faire</a><br><a href="https://craft.faire.com/mobile-performance-monitoring-at-faire-464945c9d011">Mobile Performance Monitoring</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=147093d1afcb" width="1" height="1" alt=""><hr><p><a href="https://craft.faire.com/faire-tech-talk-scaling-mobile-foundation-147093d1afcb">Faire Tech Talk: scaling mobile foundation</a> was originally published in <a href="https://craft.faire.com/">The Craft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bringing type safety to UI tests on iOS]]></title>
            <link>https://craft.faire.com/bringing-type-safety-to-ui-tests-on-ios-23426a5c48de?source=rss-f41ce1f58397------2</link>
            <guid isPermaLink="false">https://medium.com/p/23426a5c48de</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[ui-testing]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Mark Difranco]]></dc:creator>
            <pubDate>Fri, 08 Jan 2021 16:59:19 GMT</pubDate>
            <atom:updated>2022-01-18T22:50:03.774Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H48vDHeOhIJck7INTvd3rA.png" /></figure><p>Automation is the best. Who wouldn’t love making a computer do a long / complex task on your behalf? That’s why we love UI driven end to end tests so much. You can write a small amount of code upfront and reap the benefits for many years to come.</p><p>There’s many problems with basic out-of-the-box UI tests, however. They are fragile, difficult to write, and slow. Since the work the tests are performing is so complex, many things can go wrong and cause them to fail. When your tests start failing due to false positives, you trust them less, which in turn makes them useless. They’re quite laborious to write, requiring you to launch the app many times to ensure you don’t miss a step in the flow, and use clunky string queries to identify UI elements.</p><p>Since we’re growing at such a fast pace at Faire, we decided these tests were too valuable to abandon. So we started looking into how we could make our UI tests better to use.</p><p><strong>Requirements</strong></p><p>To start off, we set up a few requirements:</p><ol><li>UI tests should be easy for developers to write.</li><li>When our app changes, there should be minimal changes to the UI tests.</li><li>We should be able to minimize false positives, rebuilding confidence in our tests.</li><li>We should leverage the compiler to ensure developers can’t write an invalid test.</li></ol><p>This may seem like quite the laundry list of requirements, but all of them are important for us to have. Let’s see how we can complete all these requirements by taking a look at a typical UI test.</p><pre>func test_searchForAProduct() {<br>    // Login<br>    app.textFields[&quot;Email&quot;].tap()<br>    app.textFields[&quot;Email&quot;].typeText(email)<br>    <br>    app.secureTextFields[&quot;Password&quot;].tap()<br>    app.secureTextFields[&quot;Password&quot;].typeText(password)</pre><pre>    app.buttons[&quot;Log in&quot;].tap()</pre><pre>    // Select the appropriate tab<br>    app.buttons[&quot;Home&quot;].tap()</pre><pre>    // Perform a search<br>    app.navigationBars[&quot;Retailer.HomeView&quot;]<br>        .searchFields[&quot;search_textfield&quot;].tap()</pre><pre>    let query = &quot;The Best Umbrellas&quot;<br>    let textField = app.navigationBars.firstMatch<br>        .searchFields[&quot;search_textfield&quot;]<br>    textField.typeText(query)</pre><pre>    app.buttons[&quot;Search&quot;].tap()</pre><pre>    // Select a product<br>    let productName = &quot;Blunt Umbrella - Small&quot;<br>    testCase.waitForExistence(of: app.cells.staticTexts[productName]<br>        .firstMatch, timeout: 10)</pre><pre>    app.cells.staticTexts[productName].firstMatch.tap()</pre><pre>    // Add it to the bag<br>    app.buttons[&quot;add_to_bag&quot;].tap()<br>}</pre><p>The test is performing several steps, ensuring the user can login, search for a product, and add it to the cart. The UI tests run by making queries to the accessibility interface to find buttons and labels, and performing taps on those objects. This allows the test to interact with the app similarly to how a user would. By writing UI tests, you also get the added benefit of sprucing up your accessibility support when you add UI tests.</p><p>There’s several issues with the above test, however. There’s a lot of code duplication, and if we start scaling the number of UI tests, the problem will get worse. We’re also using Strings as part of the accessibility queries, which will only fail at runtime (and UI tests take a long time to run!). Finally, each query assumes the previous one performed a certain action, and if something changes, the whole thing collapses.</p><p><strong>Solution Attempt #1</strong></p><p>Let’s make an attempt to fix these issues. First, we can tackle code duplication by grouping common flows into helper functions:</p><pre>func test_searchForAProduct() {<br>    login()<br>    performSearch(query: &quot;The Best Umbrellas&quot;)<br>    addProductToBag()<br>}</pre><pre>func login() {<br>    app.textFields[&quot;Email&quot;].tap()<br>    app.textFields[&quot;Email&quot;].typeText(email)</pre><pre>    app.secureTextFields[&quot;Password&quot;].tap()<br>    app.secureTextFields[&quot;Password&quot;].typeText(password)</pre><pre>    app.buttons[&quot;Log in&quot;].tap()<br>}</pre><pre>func performSearch(query: String) {<br>    app.buttons[&quot;Home&quot;].tap()</pre><pre>    app.navigationBars[&quot;Retailer.HomeView&quot;]<br>        .searchFields[&quot;search_textfield&quot;].tap()</pre><pre>    let textField = app.navigationBars.firstMatch<br>        .searchFields[&quot;search_textfield&quot;]<br>    textField.typeText(query)</pre><pre>    app.buttons[&quot;Search&quot;].tap()<br>}</pre><pre>func addProductToBag() {<br>    let productName = &quot;Blunt Umbrella - Small&quot;<br>    testCase.waitForExistence(of: app.cells.staticTexts[productName]<br>                                      .firstMatch, <br>                              timeout: 10)</pre><pre>    app.cells.staticTexts[productName].firstMatch.tap()</pre><pre>    app.buttons[&quot;add_to_bag&quot;].tap()<br>}</pre><p>Now our actual test case is much smaller and more readable, and we’ve reduced the code duplication by storing each action in a helper function. This is a step in the right direction, but there’s more we can do. We still haven’t accomplished requirement #4. It is possible to write a UI test like the one below, which compiles fine, but will fail 100% of the time when run.</p><pre>func test_searchForAProduct_bad() {<br>    login()<br>    performSearch(query: &quot;The Best Umbrellas&quot;)<br>    login() // Fails here<br>    addProductToBag()<br>}</pre><p>Another downside to this helper function solution is the boundaries of the helper functions. Does the login method include tapping the login button? What if we want to do most of the login steps, but tap “Forgot Password” instead of “Sign In”? If you take this to its eventual conclusion, your helper functions would become more and more narrow. This increases the risk of the helper functions getting out of order, and we’re back at square 1. We’re on the right track though, let’s try tweaking it a bit.</p><p><strong>Solution Attempt #2</strong></p><p>Instead of having all our helper functions live at the root level, let’s group them by screen, like so.</p><pre>struct ProductContext: BaseContext {</pre><pre>    func tapAddToBag() {<br>        app.buttons[&quot;add_to_bag&quot;].tap()<br>    }<br>}</pre><p>We named these collections of helper functions Contexts. Each screen in our app has a Context. Each Context is a collection of functions you can perform on that screen. We’d have a single helper function for tapping “Forgot Password”, for example. But what about actions where a new screen is shown, like in the login case above? That’s where it gets interesting.</p><p>For navigation actions, we use the following 3 step pattern:</p><ol><li>The function will execute a query to perform the action.</li><li>We’ll create a context for the screen we’re navigating to. Calling a closure passed into the function as an argument, we’ll pass the next screen’s context to the closure.</li><li>Finally, we’ll perform an “unwind”, which will undo the action we performed at the beginning of the function.</li></ol><pre>struct LoginContext: BaseContext {</pre><pre>    func login(email: String, <br>               password: String, <br>               _ handleContext: (TabBarContext) -&gt; Void) {<br>        // 1<br>        app.textFields[&quot;Email&quot;].tap()<br>        app.textFields[&quot;Email&quot;].typeText(email)</pre><pre>        app.secureTextFields[&quot;Password&quot;].tap()<br>        app.secureTextFields[&quot;Password&quot;].typeText(password)</pre><pre>        app.buttons[&quot;Log in&quot;].tap()</pre><pre>        // 2<br>        let context = TabBarContext(app, testCase: testCase)<br>        handleContext(context)</pre><pre>        // 3<br>        context.selectAccountTab { (c) in<br>            c.logout()<br>        }<br>    }<br>}</pre><p>Why do this last step? This will allow us to leverage the compiler when writing our tests. We can now call two navigation helper functions in a row in our tests, and we’re guaranteed to not have the test fail. When we want to perform something on the screen that’s navigated to, we put that code within the closure. Because we pass the context for the next screen in step 2, the only helper functions available to us are the ones that can be performed on that screen, which can be enforced by the compiler.</p><p>Let’s take a look at an example test to make it a bit clearer.</p><pre>func test_searchAndOrderAProduct() {<br>    let refineSection = &quot;Brand Values&quot;<br>    let refineOption = &quot;Social Good&quot;<br>    let productName = &quot;XS Metro&quot;<br>    let quantity: UInt = 10<br>    let makerName = &quot;Blunt Umbrellas&quot;<br>    <br>    c.autoLogin() { (c) in<br>        c.selectHomeTab { (c) in<br>            c.search { (c) in<br>                c.search(for: productName) { (c) in<br>                    c.refineResults { (c) in<br>                        c.tapSection(withName: refineSection)<br>                        c.tapOption(withName: refineOption)<br>                    }<br>                    <br>                    c.tapProduct(withName: productName) { (c) in<br>                        c.adjustQuantityPicker(toValue: quantity)<br>                        c.tapAddToBag()<br>                    }<br>                }<br>            }<br>        }<br>        c.selectMyBagTab { (c) in<br>            c.checkoutOnlyMaker(makerName: makerName) { (c) in<br>                c.verify(paymentTerm: .paymentOnShipment)<br>                c.placeOrder { (c) in<br>                    c.continueShopping()<br>                }<br>            }<br>        }<br>        c.selectAccountTab { (c) in<br>            c.tapOrders { (c) in<br>                c.verifyMaker(withName: makerName, <br>                              hasOrderWithState: .processing)<br>            }<br>        }<br>    }<br>}</pre><p>With this new format, tests are much easier to read as well. We can clearly see when the test is “drilling down” to a detail screen (the indentation increases), when it performs multiple actions on one screen (the indentation stays the same), and when it navigates backwards (the indentation decreases). Because we’re using “c” to identify the Context at all levels, we can put our cursor anywhere and only have access to the helper functions that make sense at that level. Neat!</p><p><strong>Handling Different Transitions</strong></p><p>This works great for UIViewControllers, but how do UITabBarControllers and UINavigationControllers fit into it? These container view controllers show multiple child view controllers within their views, as well as some static UI in the form of bars at the top and bottom of the screen. For this, we can leverage composition.</p><p>Our BaseContext’s initializer takes in parameters that allow the parent Context to specify whether the child is embedded in a UITabBarController, UINavigationController, or is modally presented.</p><pre>class BaseContext {<br>    let app: XCUIApplication<br>    weak var testCase: XCTestCase!</pre><pre>    private(set) var tabBarContext: TabBarContext?<br>    private(set) var navigationBackContext: NavigationBackContext?<br>    private(set) var modalDismissContext: ModalDismissContext?</pre><pre>init(_ app: XCUIApplication,<br>         testCase: XCTestCase,<br>         with tabBarContext: TabBarContext? = nil,<br>         hasNavigationBack: Bool = false,<br>         hasModalDismiss: Bool = false) {<br>        self.app = app<br>        self.testCase = testCase<br>        self.tabBarContext = tabBarContext</pre><pre>        if hasNavigationBack {<br>            self.navigationBackContext = NavigationBackContext(app, <br>                                             testCase: testCase)<br>        }<br>        if hasModalDismiss {<br>            self.modalDismissContext = ModalDismissContext(app, <br>                                           testCase: testCase)<br>        }<br>    }<br>}</pre><pre>final class NavigationBackContext: BaseContext {</pre><pre>    func goBack() {<br>        ...<br>    }<br>}</pre><pre>class ModalDismissContext: BaseContext {</pre><pre>    func dismiss() {<br>        ...<br>    }<br>}</pre><p>This gives us the flexibility of indicating what bars might be present at any point in the app. This mirrors our view hierarchy exactly; we can embed or not embed any child view controller in one of these parent controllers. The Contexts can also check for the presence of the NavigationBackContext or ModalDismissContext, and handle multiple types of unwinds in a single action!</p><p><strong>Review</strong></p><p>Let’s evaluate the final solution against the requirements we listed at the start:</p><p><em>UI tests should be easy for developers to write.</em></p><ul><li>These tests are very easy for developers to write. We get code completion, and all the method names read like a sentence. It’s also easy to add tests to a new area of the app by simply creating a context for the new screens.</li></ul><p><em>When our app changes, there should be minimal changes to the UI tests.</em></p><ul><li>This strategy minimizes changes when the view hierarchy is updated. Because each query for a specific action is not repeated, we only need to change one spot when the app updates, decoupling the change from the number of UI tests we’ve written.</li></ul><p><em>We should be able to minimize false positives, rebuilding confidence in our tests.</em></p><ul><li>We can minimize false positives by detecting them in our tests, and writing more complex queries for that specific action. Because it’s not repeated, all of our tests that use the action will benefit from this.</li></ul><p><em>We should leverage the compiler to ensure developers can’t write an invalid test.</em></p><ul><li>The context via closure pattern leverages the compiler to make sure an invalid test cannot be written. If we decide to change a navigation flow, our tests won’t compile until they’re valid again, making updates faster and easier.</li></ul><p>To celebrate, let’s take a look at a video of the above test running!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*CcKh9qYc4lNcG5jb6s428w.gif" /></figure><p>This is just the beginning. There’s still so much we can build on this UI test platform, such as setting up model data on the backend before tests are run, or grouping larger common flows together using the components provided by the contexts.</p><p>Let us know what you think in the comments!</p><p>Also, if you’re interested in building cool things like this, join us! We’re hiring for iOS (and more!) in Kitchener and Toronto! See <a href="https://www.faire.com/careers">current openings</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23426a5c48de" width="1" height="1" alt=""><hr><p><a href="https://craft.faire.com/bringing-type-safety-to-ui-tests-on-ios-23426a5c48de">Bringing type safety to UI tests on iOS</a> was originally published in <a href="https://craft.faire.com/">The Craft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>