<?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 Alex Apriamashvili on Medium]]></title>
        <description><![CDATA[Stories by Alex Apriamashvili on Medium]]></description>
        <link>https://medium.com/@alexander.apriamashvili?source=rss-25aadcb41dd6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*kgjcB4s9eV0J3GnfRNh4GA@2x.jpeg</url>
            <title>Stories by Alex Apriamashvili on Medium</title>
            <link>https://medium.com/@alexander.apriamashvili?source=rss-25aadcb41dd6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 23:32:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alexander.apriamashvili/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[Stop holding your XCTests hostage]]></title>
            <link>https://medium.com/@alexander.apriamashvili/stop-holding-your-xctests-hostage-751d5b6ceb66?source=rss-25aadcb41dd6------2</link>
            <guid isPermaLink="false">https://medium.com/p/751d5b6ceb66</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[xctest]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[Alex Apriamashvili]]></dc:creator>
            <pubDate>Thu, 13 Aug 2020 12:31:53 GMT</pubDate>
            <atom:updated>2020-08-13T12:31:53.592Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XiX0AUs18um3vz6pG5GQgg.png" /><figcaption>A tram toward <a href="https://en.wikipedia.org/wiki/Norrmalmstorg_robbery">Norrmalmstorg</a>, Stockholm, Sweden. Photo by <a href="https://unsplash.com/@taisiia_shestopal?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Taisiia Shestopal</a>.</figcaption></figure><p>As your business grows, so does your feature set and codebase, the unfortunate side effect of this growth — compile time! We can combat our increased compile time by <a href="https://tuist.io/docs/usage/microfeatures/">breaking our codebase up into modules</a>; this can help to distribute the load between CPUs and minimise the scope of what needs to be recompiled. Modularisation comes with a whole range of benefits but also complications, some of these being dependency management and test execution.</p><p>This article is focusing on one of such problems — hosted unit testing bundles on iOS.</p><h3>What seems to be the problem?</h3><blockquote>With the growing number of separate unit testing bundles, the application is launching more often, delaying the overall test execution on both local and CI environments.</blockquote><h3>How it works</h3><p>Before jumping to the solution, let’s try to understand what the unit testing bundle is, and how hosted tests are different from the independent ones.</p><p>The unit testing bundle is a regular directory that has <em>.xctest</em> extension and contains the test executable binary, alongside all the assets necessary for the test execution, including resources and linked frameworks. Now, the difference between hosted and the independent testing bundles comes in the way how these components behave. The former type of tests is a part of the application process, which means that they run together with the application itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*T0GKVprRyzO1kgi_4N6a4A.png" /><figcaption>Testing PID and name in Xcode (Hosted)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TGQVEWh10CGtaahDSnDW-g.png" /><figcaption>Actual testing process (Application)</figcaption></figure><p>On the contrary, the independent testing bundles run in their own process, separate to the application’s process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*8yvCnfxatVeXwoTwrl8mBw.png" /><figcaption>Testing PID and name in Xcode (Independent)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FzTmA1v22XW0ANYT7iZAVA.png" /><figcaption>Actual testing process (xctest agent)</figcaption></figure><p>That nature of unit test execution means that, unlike to the independent tests, the hosted tests have no other choice, but to wait for the application to complete its launch, which is precisely the point where many large and robust projects fail to deliver optimal testing performance. The reason for that — is simply the launch time of the application, that is being rather slow.</p><h3>Solution</h3><blockquote>The most reasonable response to that problem — is to make all testing bundles independent of the application, so they don’t have to wait until it starts.</blockquote><p>Below, we are going to examine how can we make that happen and to what extent.</p><h3>Release the hostages</h3><p>First, we must define two groups of such hostages: <em>application</em> and <em>library</em> tests. While the second group is willing to be released, the first is having something similar to the <a href="https://en.wikipedia.org/wiki/Stockholm_syndrome">Stockholm syndrome</a>, that makes it inconceivable to have all tests independent.</p><h4>Application tests</h4><p><em>‘Application tests’</em> is a group of testing bundles that depends on the application by importing its module or using app APIs indirectly. If tests use <a href="https://developer.apple.com/documentation/uikit/uiwindow">UIWindow</a> or <a href="https://developer.apple.com/documentation/uikit/uiscene">UIScene</a> objects; invoke <a href="https://developer.apple.com/documentation/uikit/touches_presses_and_gestures/handling_uikit_gestures">UIKit gestures</a>, such as swipes and button taps; use system services, such as <a href="https://developer.apple.com/documentation/security/keychain_services">Keychain</a>; it is a high chance that those tests are impossible to separate with the host. Luckily, in many cases, there is only one such testing bundle in the entire project, created alongside the application. That bundle will remain hosted forever, but there is a chance to save the rest of them!</p><h4>Library tests</h4><p>Each testing bundle that belongs to the second group is supposed to test a dedicated library (<a href="https://developer.apple.com/library/archive/featuredarticles/XcodeConcepts/Concept-Targets.html">target</a>) of the project. The only requirement that one needs to fulfil to release such a test is to provide that library for testing.</p><p>Each testing bundle has a specific build setting that defines the loading locations for the dynamically linked dependencies, such as the testable library itself — the <a href="https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/RunpathDependentLibraries.html#//apple_ref/doc/uid/TP40008306-SW1">Run-Path</a> or <strong>@rpath</strong>. This variable contains a list of possible routes to the required dynamic libraries. For statically linked libraries, all symbols reside inside the testing bundle executable, when un-hosted.</p><p>It is crucial to understand another big difference between the hosted and the independent tests before moving forward — the placement. While the application tests, provided as plugins to that application, become a part of the resulting app bundle; library tests are supposed to stay outside that bundle, on the same level with the app. That essentially allows them to run independently from the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OkD1bsJLmRgd-vVr9Nr85w.png" /><figcaption>Application tests hosted inside the app bundle</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PKkZCxk4PGh5CGChOz42UQ.png" /><figcaption>Library tests residing outside the app bundle</figcaption></figure><blockquote>To un-host a testing bundle, specify <strong>Host Application</strong> in General Settings to <strong>None</strong>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XjLU6E_RIKQZW2w38zkj4A.png" /><figcaption>Unit Testing Bundle → General → Host Application: None</figcaption></figure><p>Now run tests and see that the application is no longer starting for that un-hosted bundle. Of course, for the more advanced projects, changing a single build setting won’t be sufficient.</p><h4>Ransom</h4><p>Remember the requirement we mentioned earlier, that each testable library must be there for testing? Guess what, these testable libraries won’t simply let their captives go, they need something in return. The catch is that the application bundle used to provide those libraries with all the necessary dependencies for free; now, to make it work, one needs to ensure availability of all those components for each of the testable libraries.</p><p>Luckily, Xcode provides us with such opportunity: all we need to do is to specify all modules imported inside that testable library as its <em>Target Dependency</em>. Then, repeat that operation for each of the specified target dependencies until the last module in the dependency graph. That will ensure that your testable library is capable of being compiled.</p><h3>What are the numbers</h3><p>This article would not be whole without numbers. Below, are the results of the un-hosting of a rather large project that contained <em>180</em> unit testing bundles at the time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iWx-ztS5xaA9294mhKc2PQ.png" /><figcaption>The chart that shows the effects of the un-hosting of the tests on the overall testing time on CI</figcaption></figure><p>At the beginning of the project, the overall unit test execution on CI was at around <em>40</em> minutes, with the time spent on actual testing at only about <em>6</em> minutes. That means that execution overhead at that time was unspeakable <em>34</em> minutes! At the end of the project, when almost all library tests were un-hosted, the execution overhead has dropped to just <em>9</em> minutes, bringing the overall CI testing runtime to slightly above <em>16</em> minutes. It means that the fact that tests don’t wait for the application launch phase to complete has resulted in the <em>60%</em> saving of the overall test execution time. The overhead time has dropped even further, by <em>73%</em>. The reason for that difference was in the fact that the code base of unit tests has increased by 21<em>%</em>, leaping up from around <em>22,700</em> to almost <em>27,600</em> unit test cases at the end of the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iGvxIqUxoKTM1lJYbF8KsQ.png" /><figcaption>Test numbers growth during the un-hosting project.</figcaption></figure><h3>Conclusion</h3><p>While moving fast, it is natural to have some pieces missing in the puzzle. The important thing here is to be able to find those pieces and put them back. Modularisation is a crucial part of the evolution of substantial projects, without it — there is absolutely no way to move forward in the modern world of mobile application development. It is also difficult to imagine such projects without a robust shield in the form of tests. Having these two aspects (modularisation and tests) working together is critical while accomplishing more excellent results allowing your business to grow even further.</p><p>Modularisation, accompanied by a mature testing setup, allows another excellent enhancement for the development experience — the <a href="https://martinfowler.com/articles/rise-test-impact-analysis.html">Test Impact Analysis (TIA)</a> and selective execution avoidance, that I would be delighted to share about in my future articles.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=751d5b6ceb66" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>