<?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 Jubin Jacob on Medium]]></title>
        <description><![CDATA[Stories by Jubin Jacob on Medium]]></description>
        <link>https://medium.com/@jubinjacob19?source=rss-ce2896e4af8a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*RIK3dZj3Lgr10tSq.</url>
            <title>Stories by Jubin Jacob on Medium</title>
            <link>https://medium.com/@jubinjacob19?source=rss-ce2896e4af8a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 19:59:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jubinjacob19/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[Using Distributed Testing to speed up build times]]></title>
            <link>https://medium.com/@jubinjacob19/using-distributed-testing-to-speed-up-build-times-6a5999f3d070?source=rss-ce2896e4af8a------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a5999f3d070</guid>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[continous-integration]]></category>
            <category><![CDATA[xcodebuild]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Jubin Jacob]]></dc:creator>
            <pubDate>Fri, 03 Jul 2020 06:00:04 GMT</pubDate>
            <atom:updated>2020-07-03T07:22:06.940Z</atom:updated>
            <content:encoded><![CDATA[<h3>Using Distributed Testing to speed up iOS build times</h3><p>This article is about how we managed to bring down our build times by more than 50% by using xcodebuild’s support for distributed testing.</p><p>Though we had used <a href="https://app.bitrise.io/">bitrise</a> for CI, we can use the same technique in other CI platforms like circleci, jenkins etc.</p><p>Even though xcodebuild allows us to do parallel testing by using the argument parallel-testing-enabled, we had found that the simulators start crashing when we increase the worker count more that 3. In the build machines where the configuration was much lower than our development machines, we could not increase the worker count more than 2.</p><p><strong>Distributed Parallel Testing</strong></p><p>Distributed Testing can be enabled by making use of the following options in xcodebuild: build-for-testing &amp; test-without-building . These are the steps to perform distributed testing:</p><ul><li>Create a build which can be used for distributed testing using build-for-testing,</li><li>Shard your tests so that they can be run in parallel</li><li>Run your tests in parallel in distributed machines using test-without-building</li></ul><p><strong>Build for Testing</strong><br>This is how you’d usebuild-for-testing for building an xcode project without running the tests.</p><pre>xcodebuild build-for-testing [-workspace &lt;your_workspace_name&gt;] [-project &lt;your_project_name&gt;] -scheme &lt;your_scheme_name&gt; -destination &lt;destination-specifier&gt;</pre><p>For an iOS project with a reasonable size it usually takes several minutes to do a clean build. <br>In distributing testing, since the tests are executed in different machines, it’d be preferable not to build multiple times.<br>Normally the build output is written to your derived data and the next time you run test-without-building, the build information is read from the derived data.</p><p>In the case of distributed testing, you’d want to explicitly pass the derived-data path as -derivedDataPath. The artifacts stored in the folder specified can be passed to the other build machines where you intend to perform distributed testing.</p><p><strong>Sharding Tests</strong></p><p>Sharding is the practice of splitting something over distributed machines. It is usually used in the context of databases. <br>For distributed testing, to split the test suite across distributed machines, we use the same technique. I’ve added a simple <a href="https://gist.github.com/jubinjacob19/64c280fd2ea5943c2028e12808fa324e">python script</a> to do a rudimentary sharding.</p><p><strong>Test without Building</strong></p><p>This is how to run the tests without building the project.</p><pre>xcodebuild test-without-building [-workspace &lt;your_workspace_name&gt;]  [-project &lt;your_project_name&gt;] -scheme &lt;your_scheme_name&gt; destination &lt;destination-specifier&gt; [-only-testing:&lt;test-identifier&gt;] -derivedDataPath &lt;your_derived_data_path&gt;</pre><p>Note the use of the argument -only-testing . This is so that only the subset of tests obtained from sharding are run. The argument -derivedDataPath is used to pass the derived data obtained from the first build-for-testing step.</p><p>Using these, depending on the number of concurrent builds supported by your CI provider, you can reduce the build times drastically. <br>Note that the details of spawning jobs in multiple build machines might differ between each CI provider and hence I have not mentioned those details in this article.</p><p><strong>Further Reading</strong></p><p><a href="https://developer.apple.com/library/archive/technotes/tn2339/_index.html">https://developer.apple.com/library/archive/technotes/tn2339/_index.html</a><br><a href="https://developer.apple.com/videos/play/wwdc2018/403/">https://developer.apple.com/videos/play/wwdc2018/403/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a5999f3d070" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dealing with the flakiness of UI Tests]]></title>
            <link>https://medium.com/@jubinjacob19/dealing-with-the-flakiness-of-ui-tests-e2ec64e15da5?source=rss-ce2896e4af8a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2ec64e15da5</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[Jubin Jacob]]></dc:creator>
            <pubDate>Thu, 19 Mar 2020 04:18:55 GMT</pubDate>
            <atom:updated>2020-05-21T10:56:40.078Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to deal with the inherent flakiness of Xcode UI Tests using xcodebuild, PlistBuddy and some shell-script</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mzn_B7a-iAURDKfBVaF7kg.png" /><figcaption>Kudos to <a href="https://lukaszadam.com/illustrations">lukaszadam.com</a></figcaption></figure><h4><strong>A brief introduction</strong></h4><p>At the company we were working in, we had our Unit Test, UI Test and Snapshot Testing targets setup and had a decent code coverage. We had our CI set up in <a href="https://app.bitrise.io/">bitrise</a> and everything was going well. <br>After migration to a newer version of Xcode, we noticed that the UI tests started to fail more often than before. Anyone who has worked in UI Tests in iOS would know that they are notoriously flaky. At first, we had thought that bitrise was to blame and had asked some of the support engineers to look into it. Later we realized that the tests were failing even in our local machines.</p><p>But the interesting thing was that the same tests which had failed when the whole UI Test suite was run, were passing when ran individually. Armed with this insight, we arrived at a solution. We would comment in the Pull Requests of failing builds if the tests were passing locally and the reviewers would verify the same.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*u8Uw0Poyl-OPghNXT6w-1Q.jpeg" /><figcaption>Image courtesy: <a href="https://knowyourmeme.com/memes/modern-problems-require-modern-solutions/photos">https://knowyourmeme.com/memes/modern-problems-require-modern-solutions/photos</a></figcaption></figure><p>It was only a matter of time before we started ignoring genuine failures in the CI server and we knew that we needed a better approach.</p><p>The solution seemed simple enough. We just had to force the CI machine to rerun the failing tests until they passed.</p><h4><strong>Xcodebuild to the rescue</strong></h4><p>After a bit of research, we found that xcodebuild did have an argument -only-testing that gave fine-grained control over which tests to run.</p><pre>&#39;-only-testing:UITests&#39; //tests the entire UI Test target<br>&#39;-only-testing:UITests/LoginTest&#39; //tests only LoginTest suite<br>&#39;-only-testing:UITests/LoginTest/testUserLogin&#39; // tests only the testcase testUserLogin </pre><p>After some more digging around, we decided that the file named TestSummaries.plist would be the best place to do this. This file is generated at the path which is passed as the argument resultBundlePath to xcodebuild.</p><h4><strong>Parsing a .plist file</strong></h4><p>Property List (plist) files are ubiquitous in mac and iOS development but it is kind of hard to parse it in a shell script. We used the utility PlistBuddy to parse the plist. Each test case had its status of Success/Failure stored in the plist.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GlMzb5Q839Gabc1Pduu__Q.png" /><figcaption>TestSummaries.plist</figcaption></figure><p>As can be seen from the screenshot the test result is stored in the key TestStatus.</p><p>We converted all this into a shell script and after updating our CI workflow we now started seeing results. The CI stopped giving false-negative results and almost all the build failures were due to programing errors.</p><p>You can find the open sourced version of the script <a href="https://github.com/jubinjacob19/XCTestHelper">here</a>.</p><p><strong>Note</strong></p><p>The fastlane plugin test_center has an action <a href="https://github.com/lyndsey-ferguson/fastlane-plugin-test_center/blob/master/docs/feature_details/multi_scan.md">multi_scan</a> which allows you to re-run flaky tests.</p><h4><strong>Further Reading</strong></h4><ul><li><a href="https://developer.apple.com/videos/play/wwdc2016/409/">Advanced Testing and Continuous Integration - WWDC 2016 - Videos - Apple Developer</a></li><li><a href="https://github.com/jubinjacob19/XCTestHelper">jubinjacob19/XCTestHelper</a></li></ul><p><a href="https://github.com/lyndsey-ferguson/fastlane-plugin-test_center">https://github.com/lyndsey-ferguson/fastlane-plugin-test_center</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2ec64e15da5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Beginner’s Guide to Code Coverage]]></title>
            <link>https://medium.com/@jubinjacob19/the-beginners-guide-code-coverage-4e3c60e11d85?source=rss-ce2896e4af8a------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e3c60e11d85</guid>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[unit-testing]]></category>
            <dc:creator><![CDATA[Jubin Jacob]]></dc:creator>
            <pubDate>Wed, 23 Oct 2019 05:53:29 GMT</pubDate>
            <atom:updated>2020-01-05T21:44:32.147Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to automate ensuring minimum coverage in iOS projects</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7fD2eW2_heDu6Cv3bGTMoA.gif" /><figcaption>Binary animation by <a href="https://dribbble.com/JacobBurghart">Jacob Burghart</a></figcaption></figure><p>Let’s start by looking at the definition of Code Coverage:</p><blockquote>Code coverage is a measure used to describe the degree to which the source code of a program is executed when a particular test suite runs. A program with high code coverage, measured as a percentage, has had more of its source code executed during testing, which suggests it has a lower chance of containing undetected software bugs compared to a program with low code coverage.</blockquote><p>So, by definition, a project with more test coverage is less prone to undetected bugs than a project with less test coverage. If that is not a good enough reason for you to strive for good coverage in your project, here is another one: Everyone loves a good metric.</p><p>For a new project/existing project without any tests, the following strategy is advisable: Write some meaningful tests without worrying too much about the overall coverage. Once you have a decent test suite built, ensure that while developing future requirements, the amount of coverage is maintained and the test suite does not degenerate.</p><p>First, arrive at some minimum code coverage percentage. The number can vary from team to team and project to project. In any case, it should not be lesser than the coverage that you currently have.<br>Then add a step to the CI/CD pipeline that ensures that for every commit, the code coverage percentage is always greater than the minimum value that had been set. Also, export the coverage reports in a human-readable format as build artifacts in the CI/CD portal.</p><p>Easier said than done. Let’s look at how to do this on iOS.</p><p>The first thing to do is to enable coverage only for the targets we are interested in. Open the scheme editor in Xcode and select the option “Gather Coverage Report for”. Change the option from “all targets” to “some targets” and select only the targets whose coverage you are interested in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9ozx3W93pz3Sjtws5PWUcg.png" /></figure><p>This ensures that while running unit/ui tests using xcodebuild, the coverage reports will also be generated. By default, the coverage reports are stored in the Derived Data directory. Pass the argument resultBundlePath to override that as below:</p><pre>xcodebuild -workspace &lt;workspace_name&gt; -scheme &lt;scheme_name&gt; -destination &#39;&lt;destination_device&gt;&#39; -resultBundlePath &lt;result_directory&gt; test</pre><p>Substitute result_directory with the directory you want to store the results in. After running the tests, the results directory will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*u5RIsvgGuv44b4hdFOR3-A.png" /><figcaption>results_directory</figcaption></figure><p>The file&#39;s action.xccovarchive and action.xccovreport are the ones we are interested in. In case, you are running the unit tests and UI tests separately, the coverage reports for these needs to be merged. Fortunately, xccov has an option to do exactly that.</p><pre>xcrun xccov merge --outArchive out.xccovarchive --outReport out.xccovreport action1.xccovreport action1.xccovarchive/ action2.xccovreport $action2.xccovarchive/</pre><p>where action1 and action2 are the xccovreports and xccovarchives corresponding the 2 different tests. The merged report will be generated in the locations out.xccovarchive and out.xccovreport.</p><p>This is how to view the xccovreport file:</p><pre>xcrun xccov view out.xccovreport // human-readable<br>xcrun xccov view --json out.xccovreport // machine-readable</pre><p>The human-readable view will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yB-B1IM7GpNE6RkuIE41ew.png" /><figcaption>Shameless plug here, that’s my open-source pattern-lock component. And you saw it right, I’m guilty of not adding any tests there!</figcaption></figure><p>Finally to parse the coverage percentage and to validate that it is greater than the defined minimum value. Though we have the option to read from json view, I’d prefer parsing the human-readable report because text parsing is much easier than json parsing in bash.</p><pre>xcrun xccov view out.xccovreport &gt; coverage.txt<br>#upload coverage.txt as build artifact to your CI<br>#substitute target_name with your target<br>coverage_percent=$(grep &quot;PatternLock.framework&quot; coverage.txt| grep -o &#39;[^ ]*%&#39;)<br>#to extract the integer part of the coverage percentage<br>coverage=${coverage_percent%.*}<br>#set MINIMUM_COVERAGE as your ideal minimum coverage value<br>if [ $coverage -ge $MINIMUM_COVERAGE ]; then<br>    exit 0<br>else<br>     exit 1<br>fi</pre><p>This script should mark the build as failed if the coverage is not at par with the expected value.</p><h4>Final Thoughts</h4><ul><li>It is always a good practice to try and automate mundane tasks.</li><li>Though good coverage could be indicative of the code quality, it does not guarantee that the code is bug-free and it is up to the developers to ensure that there are meaningful tests.</li><li>The coverage percentage is what it is, a number, and we shouldn’t be writing meaningless tests that exist just for meeting the minimum coverage requirement.</li></ul><p><strong>Suggested watching</strong></p><p><a href="https://developer.apple.com/videos/play/wwdc2018/403/?time=98">What&#39;s New in Testing - WWDC 2018 - Videos - Apple Developer</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e3c60e11d85" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Speeding up Automated Tests in iOS]]></title>
            <link>https://medium.com/@jubinjacob19/speeding-up-automated-tests-in-ios-fdf20080710e?source=rss-ce2896e4af8a------2</link>
            <guid isPermaLink="false">https://medium.com/p/fdf20080710e</guid>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[Jubin Jacob]]></dc:creator>
            <pubDate>Mon, 21 Oct 2019 08:11:31 GMT</pubDate>
            <atom:updated>2019-12-10T17:04:46.626Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sJatMnNrTIuyY3nwlph8Rw.png" /><figcaption>This great image comes from <a href="https://icons8.com/ouch">Icon8</a></figcaption></figure><p>If you have been writing UI Tests for your iOS applications and have been frustrated by the amount of time it takes to run the full test suite, read on. If you have not been writing UI Tests at all, I’d advise starting now, it is never too late.</p><p>We have been using B<a href="https://www.bitrise.io/">itrise</a> as our CI/CD platform. With more feature additions, out test suites started to grow and very soon our builds started timing out very often. The reason was that the maximum build time was capped at 90 minutes and sometimes our builds exceeded that. (Yes, you read that right, &gt;90 minutes for running the tests!). So any time saved was important since it would help us avoid the timeouts.</p><p>Initially, we had tried with parallel testing enabled, but that didn’t work very well in the bitrise machine. We are assuming it was because the build machines were not powerful enough for the parallelization to have a meaningful effect. So we had to resort to other means.</p><p>We decided to take a shot at speeding up/disabling the animations so that we save the time lost in all the transition animations. We added the following code snippet in AppDelegate to disable animations and to set the key window’s layer speed to a very high value.</p><pre>UIView.setAnimationsEnabled(false)<br>UIApplication.shared.keyWindow?.layer.speed = 100</pre><p>While running the app after this, sure enough, the animations had become so fast that we couldn’t see the transitions.</p><p>We decided to measure the speed gain in our local machine. The results were promising; we found that for tests that involved considerable animations, we could reduce the time by more than 10 seconds each. And after running the entire test suit we found that we had brought down the time required for UI Tests to complete from 57 minutes to 46 minutes and unit tests from 4 minutes to 2 minutes.</p><p>Also, we had an unintended benefit out of this exercise. UITests are notoriously flaky in iOS and we had some tests which were failing quite inconsistently. After disabling the animations, these started failing consistently. As any developer would agree, consistent failures are always better than inconsistent successes. This enabled us to fix the broken tests and our test suite became more reliable.</p><p>Since the results were promising in the local machine, we decide to try it out in our build machines as well. But first, we had to configure such that the animations were disabled only in the testing mode. For unit tests and snapshot tests, we decided to set up an argument passed on launch DISABLE_ANIMATIONS in the scheme as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zhJgnOjmpjA4fOFD-y606A.png" /></figure><p>In case you are wondering what the other environment variables are, they are related to FBSnapshotTestCase, the Snapshot testing library that we are using. The arguments passed on launch are written to the UserDefaults, so now we could conditionally disable the animations as below:</p><pre>if UserDefaults.standard.bool(forKey: &quot;DISABLE_ANIMATIONS&quot;) {<br>   UIView.setAnimationsEnabled(false)<br>   UIApplication.shared.keyWindow?.layer.speed = 100<br>}</pre><p>However, this did not work for UI tests. We found that for UI Tests, we had to pass the environment variables in a slightly different way. Before the launch of XCUIApplication we could add launch arguments as below.</p><pre>let app = XCUIApplication()<br>app.launchArguments = [&quot;-DISABLE_ANIMATIONS&quot;, &quot;true&quot;]<br>app.launch()</pre><p>Though this meant that we had to do a find-and-replace in all the UI Test suites, it offered the flexibility that we could choose not to disable the animations for a particular UI Test if we wished to do so. Note that the launchArguments from the UI Test can be accessed the same way via UserDefaults.</p><h4>Results from Bitrise</h4><p>We found that we could reduce the time from 85 minutes to around 70 minutes (around 17%). Though this was not very drastic, it meant that we will not hit the 90 minutes timeout until some time.</p><h4>Conclusion</h4><ul><li>We found that disabling the animation for all UI Tests was an effective way to speed up the testing times. However, the time saved would be meaningful only if the app animations are a significant factor in the testing times. In any case, it doesn’t hurt to try.</li><li>In our case, disabling the animations helped us to reduce the flakiness of our tests since we could now reproduce and fix the inconsistently broken tests.</li><li>Parallel testing would also reduce the testing times provided your build machines are powerful enough.</li></ul><p><strong>Suggested Reading</strong></p><ul><li><a href="https://www.swiftbysundell.com/articles/launch-arguments-in-swift/">Launch arguments in Swift | Swift by Sundell</a></li><li><a href="https://shashikantjagtap.net/the-fast-furious-and-flaky-continuous-integration-with-xcode-10-parallel-tests/">The Fast, Furious and Flaky Continuous Integration with Xcode 10 Parallel Tests</a></li><li><a href="https://useyourloaf.com/blog/xcode-10-random-and-parallel-tests/">Xcode 10 Random And Parallel Tests</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fdf20080710e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>