<?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 Beyza Ince on Medium]]></title>
        <description><![CDATA[Stories by Beyza Ince on Medium]]></description>
        <link>https://medium.com/@beyza.ince?source=rss-a7d98cba1e38------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LqGqPSSEsgFMfEnRNlVx6g.jpeg</url>
            <title>Stories by Beyza Ince on Medium</title>
            <link>https://medium.com/@beyza.ince?source=rss-a7d98cba1e38------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 01:40:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@beyza.ince/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[Mock Generator Development With Using Mockolo Library]]></title>
            <link>https://medium.com/trendyol-tech/mock-generator-development-with-using-mockolo-library-c8c273f77d1b?source=rss-a7d98cba1e38------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8c273f77d1b</guid>
            <category><![CDATA[ios-testing]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[mockolo]]></category>
            <dc:creator><![CDATA[Beyza Ince]]></dc:creator>
            <pubDate>Wed, 17 May 2023 06:48:17 GMT</pubDate>
            <atom:updated>2023-05-17T06:48:17.148Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bobTrtZkyUUCc78V89C4Dw.jpeg" /></figure><p>As the iOS team at Trendyol, we write unit tests for the logic implemented in presenter or manager classes. To ensure stability in all scenarios, we inject all classes into the presenter. When it comes to unit testing, we then mock all the classes within the presenter.</p><p>In this article, we’ll share our journey at Trendyol’s iOS team, where we encountered challenges with our previous mock generator, MockGeneratorForXcode, and transitioned to using Mockolo, an actively maintained library developed by Uber. We’ll explain how we developed a customized Xcode extension tool with Mockolo to align it with our existing workflow. This walkthrough covers creating the extension application, defining its functionality, accessing the protocol path, and modifying the mock generation code. By the end, you’ll gain insights into how we overcame our challenges and acquire knowledge that can be applied to similar situations in your own projects.</p><h4>Problems</h4><p>Previously, we used to generate mock classes with <a href="https://github.com/seanhenry/SwiftMockGeneratorForXcode"><strong>MockGeneratorForXcode</strong></a>. Unfortunately, this library has stopped being developed for new features. Consequently, we started to search for a new mock generator that could automatically generate functions and protocols with asynchronous definitions and also classes which in hidden folders. During our research we discovered the <a href="https://github.com/uber/mockolo"><strong>Mockolo</strong></a> library, developed by Uber, which not only addresses our needs but is also actively maintained.</p><h4>Mockolo</h4><p>Mockolo allows for the mocking of protocols on specific paths via a command-line interface (CLI). We decided to customize its usage due to its divergent approach from the existing structure within our team’s workflow. As a result, we developed an extension in a higher layer, enabling the team to continue the usage they are used to.</p><p>During the development of this application, we examined the MockGeneratorForXcode library and got help in the necessary parts. In the following section, let’s see how we implemented this extension.</p><h3>Creating an Extension Application</h3><p>To develop an Xcode extension tool, we need to first create an application.<br>Subsequently, we need to add the Xcode Source Editor extension as a new target to the application we have created. This allows us to create the extension that will be displayed within Xcode.</p><p>To ensure the secure usage of the extension, we must also include the Sandbox from the Capability section. (Sandbox is a feature that generally restricts the access of applications on the system.) Additionally, the extension we develop needs to listen to the thread on which Xcode is running. For this purpose, we must also enable Apple Events in the Hardened Runtime section.</p><h4><strong>Getting the Project Path</strong></h4><p>The developer can’t run the extension without giving the user permission to the project path where the extension will be used. To achieve this, we need to define the App Groups, which will be shared between the app and extension targets. It is recommended to start with the “group” prefix as a common convention.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ucb-pmwfL1J3obtEM5UJfA.png" /></figure><p>On the application side, we need to prompt the user to select the project path and ensure that the chosen path is registered in the User Defaults using the designated path within the App Groups. This User Defaults data will be shared and utilized when running the extension. To achieve this, we need to create bookmark data for the selected path and save it to User Defaults.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5aed43eb3bd53ee1278144990ff8686a/href">https://medium.com/media/5aed43eb3bd53ee1278144990ff8686a/href</a></iframe><h4>Creating Extension Button</h4><p>Now we reach the step of running the extension. To accomplish this, we need to begin by defining the data that we want to display as a button in our extension in the Info.plist file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Jt7h3Ilsh3UA59ZcS9uyg.png" /></figure><p>As our extension is solely dedicated to the Mock generation command, we have made a singular definition for its functionality.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dfd324ed1126e113ccef7d71bd6684d1/href">https://medium.com/media/dfd324ed1126e113ccef7d71bd6684d1/href</a></iframe><p>Upon pressing the “Generate Mock” button, the perform function in the class will automatically execute. The invocation parameter in this function allows access to all the code within the class where the extension is running. This enables us to access the desired protocol that we want to generate a mock for.</p><h4>Real World Example</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Thyj14j-IkFPHwxwC1Z8fg.png" /></figure><p>For example, let’s generate the <strong>MockBasketInteractor</strong> class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7m1HHwKogpJfjcMv-xFf9w.png" /></figure><p>First, we find the <strong>BasketInteractorInterface</strong> protocol over invocation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c443b5c8efeacbeac9eac4f09344b4d7/href">https://medium.com/media/c443b5c8efeacbeac9eac4f09344b4d7/href</a></iframe><p>We do not have information about the specific file in the project where the specified protocol is located. To determine this, we need to access all the project files and search for the protocol. To achieve this, we first need to access the Workspace that is open in Xcode. The code snippet below demonstrates how to accomplish this by running a script and accessing the relevant workspace.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4ed21103aa622400ca1f05fa52595f4/href">https://medium.com/media/b4ed21103aa622400ca1f05fa52595f4/href</a></iframe><p>Once we have successfully accessed the Workspace, our next step is to scan through all the files and gather the ones with a “.swift” extension.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7926875fc4b15f8f954b21517b3580f8/href">https://medium.com/media/7926875fc4b15f8f954b21517b3580f8/href</a></iframe><p>In order to verify the presence of the relevant protocol within the swift files we have accessed, we execute the following function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/95ebbe0e6a2aaf74dc689bc0505de14d/href">https://medium.com/media/95ebbe0e6a2aaf74dc689bc0505de14d/href</a></iframe><p>All the work so far has been to find the protocol path. In the following section, we will talk about how we tailor the organization to align with our workflow.</p><p>Due to the disparity between our mock structure and the Mockolo library, we needed to modify the code responsible for generating mocks within the library.</p><p>To achieve this, we made the Executor class in Mockolo public and transformed it into a structure that can be accessed within our own project. This allows us to conveniently pass the protocol path as a parameter to the Executor and generate the mock with ease.</p><h4>CLI Part</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4115f841477b476c5747b33ee1215753/href">https://medium.com/media/4115f841477b476c5747b33ee1215753/href</a></iframe><p>As a result of the aforementioned process, the mock class we generate will be stored in the Output class. As we cannot directly perform the generation operation within the class, we temporarily write the output.swift file within the extension. The next step involves writing the mock data from this class to the corresponding class within the project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/55a8ef508c4230b882a28aa4a5878f05/href">https://medium.com/media/55a8ef508c4230b882a28aa4a5878f05/href</a></iframe><p>To generate the mock, we write the mock file created in the above function into the targeted class within the project. We utilize the invocation parameter for this write operation as well. After completing all of these steps, the final version of the class we created for mock generation is as follows. This Mock structure is tailored specifically for <a href="https://github.com/aytugsevgi/SwityKit"><strong>SwiftyKit</strong></a>, which we developed within our team.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DIhKB6_xPayMSpXfc4TZlA.png" /></figure><p>In conclusion, we have developed an up-to-date library to address the issues related to mocking within our team. If you have any further adjustments or specific requirements for the concluding paragraph, please let me know!</p><p><strong>If you want to be part of a team that tries new technologies and want to experience a new challenge every day, come to us.</strong></p><p><a href="https://jobs.lever.co/trendyol?department=Engineering%2C%20Technology%20%26%20Product">Trendyol jobs</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8c273f77d1b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trendyol-tech/mock-generator-development-with-using-mockolo-library-c8c273f77d1b">Mock Generator Development With Using Mockolo Library</a> was originally published in <a href="https://medium.com/trendyol-tech">Trendyol Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Distribute Unclear Responsibilities in The Team With Automation]]></title>
            <link>https://medium.com/trendyol-tech/distribute-unclear-responsibilities-in-the-team-with-automation-70eac66fb6e9?source=rss-a7d98cba1e38------2</link>
            <guid isPermaLink="false">https://medium.com/p/70eac66fb6e9</guid>
            <category><![CDATA[vapor]]></category>
            <category><![CDATA[fluent]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Beyza Ince]]></dc:creator>
            <pubDate>Mon, 01 Aug 2022 11:02:05 GMT</pubDate>
            <atom:updated>2022-08-02T06:10:10.919Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8b8aHYpD91jxQGvHkyhGWQ.jpeg" /></figure><p>Having a lot of developers in a single repo often creates bottlenecks for processes like PR review and automation. Carrying out all these operations manually is troublesome and has a high margin of error. For this, we try to develop most of the processes we use internally by automating them. In a moment, we will explain in detail how some of these processes work.</p><h4>PR Reviewer Selection Process</h4><p>One of the essential processes in the Trendyol iOS team is to identify the developers who will review the PRs. Since there are too many PRs, it is not possible for everyone to look at every PR. That’s why we decided to determine the developers who will review the PRs with a specific ruleset. The iOS team is divided into many small teams within itself. Still, since the whole project proceeds with the same codebase, people in different teams can review the PRs of other groups without being alienated.</p><p>People who will review the PR are randomly selected among all developers, two from the PR owner’s team and four from the other groups, and everyone’s responsibility pre-determined. Anyone can be a reviewer and check the PR than these six people. When a new PR is opened, people added to the previous PR will not be added again unless all developers are added to a PR.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*YxiSg6dFcVpSawuxyGYUMg.png" /><figcaption>add reviewers to PR</figcaption></figure><h4>New Candidate Case Reviewer Selection Process</h4><p>One of the essential stages in new candidate interviews is to examine the candidate&#39;s case and give the necessary feedback. Six people are randomly selected among the developers to determine who will review the case. When a new candidate project arrives, people added to the previous candidate projects will not be added again until all developers are added to any candidate project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*lqKvlC3BfdKqLgrBUfAroQ.png" /><figcaption>add reviewers for candidate case review</figcaption></figure><p>As with the developers, random assignments are made to the QAs to review the incoming cases in the new candidate interviews. As a difference in QA teams, the selection is made among all QA friends in both Android and iOS groups.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*0leraJpdqUMxnaES-UYqvw.png" /><figcaption>add reviewers for QA candidate case review</figcaption></figure><h4>Vacation Mode</h4><p>The biggest problem when choosing developers and QAs for PR or case reviews is that they can still be selected as reviewers when they are on leave. It can cause a bottleneck, especially in summer. To solve this problem, we added vacation mode to our automation processes. When the developer or QA on leave enables the vacation mode, he/she is not assigned as a reviewer to any pr or case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*ELiUgd4WMGMov6Ul9Tpe2A.png" /><figcaption>enable vacation mode</figcaption></figure><p>After returning from leave, they disable vacation mode and can be selected as a reviewer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*7cvmts_qVoM3A0v7Xo4n1A.png" /><figcaption>disable vacation mode</figcaption></figure><h4>Add A New User</h4><p>Friends who have just joined the team must be included in the system to be assigned to the pr and case review processes. We do this with automation that listens to Slack channels. In order for the automation processes to understand the newly joined user name, whether he is a developer or a QA, it is sufficient to execute the comment below where the role and the name of the team he/she joined needs to be specified.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*jl0B6Q2aji6RWr_nhn4DEQ.png" /><figcaption>add new user</figcaption></figure><h4>Used Technologies</h4><p>There are several different technologies used in the back for the management of the whole process.</p><p>We keep users’ information in tables on PostgreSQL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f8IKdUvnxquHoI_J4fyUVA.png" /><figcaption>user table structure</figcaption></figure><p>We use the <a href="https://docs.vapor.codes/fluent/overview/">Fluent</a> framework provided by Vapor to access this data and use it wherever we want.</p><p>Fluent supports adding, updating, filtering, and deleting database operations using Swift language.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*eSAhy-Bq9LgJdk2az2vDpQ.png" /><figcaption>user table structure in Fluent project</figcaption></figure><p>As <a href="https://medium.com/trendyol-tech/the-effect-of-bots-on-automation-fb3135908632">previously</a> explained, we run the remaining parts of the automation processes through a bot called Skynet.</p><p>As a result, we achieved automating our reviewer selection process efficiently. If you have any questions, feel free. Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70eac66fb6e9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trendyol-tech/distribute-unclear-responsibilities-in-the-team-with-automation-70eac66fb6e9">Distribute Unclear Responsibilities in The Team With Automation</a> was originally published in <a href="https://medium.com/trendyol-tech">Trendyol Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automated Visual Testing With Snapshots: Part 2]]></title>
            <link>https://medium.com/trendyol-tech/automated-visual-testing-with-snapshots-part-2-19354052c6d9?source=rss-a7d98cba1e38------2</link>
            <guid isPermaLink="false">https://medium.com/p/19354052c6d9</guid>
            <category><![CDATA[ui-test-automation]]></category>
            <category><![CDATA[snapshot]]></category>
            <category><![CDATA[xcuitest]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[jenkins]]></category>
            <dc:creator><![CDATA[Beyza Ince]]></dc:creator>
            <pubDate>Thu, 25 Nov 2021 13:00:12 GMT</pubDate>
            <atom:updated>2021-11-25T13:00:12.971Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/558/1*n1vpHDmntlay17xcH2DGWQ.gif" /></figure><p>The beautiful part of the structure we built actually starts here. Let’s say a new feature has been developed and a new button has been added to some page and your snapshot tests detect it and fail.<br>You have to update the tests in traditional tests, right? It’s as easy as clicking the button here. Since the reference image will be updated, you are updating the tests without writing any code.</p><h4><strong>Customize Snapshot Testing Library</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Fj1WpqqZCuskiqjfdqNJA.png" /><figcaption>Customize output folder paths</figcaption></figure><p>We forked the swift-snapshot-testing library and customized the path to the file folder where we will save the reference and failure files. We changed the reference and failure image paths for Jenkins. We didn’t store images inside the project to avoid an increase in project size. In this way, we can store Snapshot images in the same virtual machine in a folder outside the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0IBiqtAV8LxwYlQBV_U2rQ.png" /></figure><p>We created a new lane for snapshots in FastFile and separated the test plan.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/470244fec3f744bf93adc0238678d665/href">https://medium.com/media/470244fec3f744bf93adc0238678d665/href</a></iframe><h4>Jenkins Script</h4><p>We trigger the tests thanks to a job we created in Jenkins. The script working in this job is as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/47bd702e8395c5fa077df79a60cf5cf8/href">https://medium.com/media/47bd702e8395c5fa077df79a60cf5cf8/href</a></iframe><p>Before running tests, we clean the folder where we keep the snapshot images that fail. Images of failed tests will be added back to this folder. After running all the tests, we need to check if there are any files in this folder. For this, we get the names of the files with a small terminal code(line 11). If there is any filename, it means the test is failed.</p><p>Since there are processes running on the virtual machine, we let two simulators run in parallel to ensure stability.We couldn’t access the error file from outside of the virtual machine. To upload the image of the error file to Slack as a message, we send a request in the Jenkins script.(line 16)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*RnmU7izAJCZkrCa_96eKfw.png" /></figure><p>We added 3 buttons in Slack message.</p><ul><li>In order to see the reference file we added <strong>Show Reference Picture</strong> button.</li><li>To able to update the reference file of a Snapshot test, we display <strong>Update</strong> button using the Slack API in the service we developed and send them to the Slack channel.</li><li>For reasons similar to the rerun feature that came to XCode 13, we added a <strong>Rerun Test</strong> button for a single test to run again. Using the feature that build-for-testing provides us, we can control the test without re-build by specifying a single test name.</li></ul><p>The resulting image showing the difference of failed and reference files may not be very explanatory. That’s why we decided to send the reference and failure images to the channel separately. In cases where we couldn’t understand the difference, we can look at the difference between the two images manually with the images comparison tools.</p><h4>Update Reference Image</h4><p>To update the reference images, we trigger the Jenkins job below. If the job finishes with success, we send a success message to Slack via the service we use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FiYuaRyHbmVj3Zey0iNAVQ.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1f2e5d7fa12ddadd3b67f6045d79e93/href">https://medium.com/media/a1f2e5d7fa12ddadd3b67f6045d79e93/href</a></iframe><p>At the beginning of this process, we followed the results of all tests with the QA team on a common slack channel. We made a POC first then ran all the tests and iterate every day.<br>We realized that this process wasn’t practical and requires a lot of effort so we divided the responsibilities by channel and increased the traceability.<br>We prepared these tests separately for 5 different channels in Trendyol and created a separate Slack channel. If all tests in the channel run successfully, we send a notification for that result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*iCRVyuMLFqrF4Oedk3-png.png" /></figure><h4>What is Next</h4><ul><li>Sending difference images to slack channel using image exporter tool.</li><li>Adding a new button to the Slack message of failed Snapshot tests. That will automatically open the bug task by adding the name and picture of the test to the Jira of the related team’s board.</li></ul><p>In conclusion, we added Snapshot testing in CI/CD process. Thank you for reading. If you have any questions, feel free to contact me and <a href="https://medium.com/u/c830985ced1f">Atakan Karslı</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19354052c6d9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trendyol-tech/automated-visual-testing-with-snapshots-part-2-19354052c6d9">Automated Visual Testing With Snapshots: Part 2</a> was originally published in <a href="https://medium.com/trendyol-tech">Trendyol Tech</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 Write Unit Tests for Selector Functions in Swift]]></title>
            <link>https://medium.com/trendyol-tech/how-to-write-unit-tests-for-selector-functions-in-swift-109fe13756c0?source=rss-a7d98cba1e38------2</link>
            <guid isPermaLink="false">https://medium.com/p/109fe13756c0</guid>
            <category><![CDATA[selector-functions]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Beyza Ince]]></dc:creator>
            <pubDate>Fri, 11 Jun 2021 14:29:37 GMT</pubDate>
            <atom:updated>2021-06-11T14:29:37.664Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RdZB8hkVWdTv9YHQYH79YQ.png" /></figure><p>In the Trendyol iOS project, we write unit tests for the codes in the <strong>presenter</strong> classes. We use <strong>Slather</strong> as a code coverage tool for our unit tests and based on its result we add unit tests for the uncovered code blocks. While writing unit tests, we realized that functions defined with the selector attributes cannot be tested like other functions. Before solving this problem, let’s take a look at how we define functions with selector attributes.</p><h3>Selector Functions</h3><p>In the example below, I tried to show the sample selector functions we use. We need to define the <strong>objc</strong> attribute at the beginning of the functions to use the <strong>selector</strong> attribute. Since these functions cannot be called from anywhere outside of the class, we limit their accessibility by adding the <strong>private</strong> attribute.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jl0ifCur97sHZGOJQJqmew.png" /><figcaption>1.1. Selector functions example</figcaption></figure><p>We define the functions that will work on the click action with the selector attribute as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rYARYjypPjASd0W3qYxiaA.png" /><figcaption>1.2. Selector function set example</figcaption></figure><p>We wanted to write the unit tests for these functions, but the private attribute of the functions prevented us from accessing them directly. In order to solve this problem, we decided to trigger the function using the selector parameter in that I showed in the 1.2. picture.</p><p>While writing unit tests, we use a mock version of classes and we create these with <a href="https://github.com/seanhenry/SwiftMockGeneratorForXcode">SwiftMockGeneratorForXcode</a>. In this way, we can easily check whether the logics in the <strong>presenter </strong>classes call the referenced classes successfully. I added the view class function’s mock version in the picture below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yCb2tNdbI_eL40S6mbeffg.png" /><figcaption>1.3. Mock view function example</figcaption></figure><p>In the unit tests, we triggered the function with selector parameter in the presenter classes and ensured that the selector function is assigned to the selector parameter of this function in the mock view. When we trigger this selector parameter, we will be able to test the selector function. In the picture 1.1., the <strong>dismissButtonTapped</strong> function calls the router class’s <strong>popupModule </strong>function with an animated parameter. We also created the mock version of the router to make it testable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wZIxUmR13l2U-pMZaeXZHw.png" /><figcaption>1.4. Mock router function example</figcaption></figure><p>We accessed and triggered the selector functions in the unit tests as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6Y3-18q-XiVXptPMQ7CLpw.png" /><figcaption>1.5. Selector unit test example</figcaption></figure><p>By using the <strong>Thread.detachNewThreadSelector </strong>function, the selector function can be found. <strong>DetachNewThreadSelector</strong> as Apple documentation <strong>“detaches a new thread and uses the specified selector as the thread entry point”</strong>. In order to understand whether the function is working, we make the necessary controls asynchronously in the main queue.</p><p>In conclusion, we found a proper way to write unit tests for selector functions. Thank you for reading. If you have any questions, feel free to contact me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=109fe13756c0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trendyol-tech/how-to-write-unit-tests-for-selector-functions-in-swift-109fe13756c0">How to Write Unit Tests for Selector Functions in Swift</a> was originally published in <a href="https://medium.com/trendyol-tech">Trendyol Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mocking API Calls in UI Tests]]></title>
            <link>https://medium.com/trendyol-tech/mocking-api-calls-in-ui-tests-b908dbf6b305?source=rss-a7d98cba1e38------2</link>
            <guid isPermaLink="false">https://medium.com/p/b908dbf6b305</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ui-testing]]></category>
            <category><![CDATA[mock-api]]></category>
            <category><![CDATA[swifter]]></category>
            <category><![CDATA[parallel-testing]]></category>
            <dc:creator><![CDATA[Beyza Ince]]></dc:creator>
            <pubDate>Tue, 25 May 2021 06:13:56 GMT</pubDate>
            <atom:updated>2021-05-25T10:06:43.037Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wFS14-cE6y6uoR56cb2cGQ.jpeg" /></figure><p>Testing process is essential in the Trendyol iOS application. It helps us to increase maintainability and reduce the possibility of feature problems. There are various kinds of user scenarios in application UI but it is hard and time-wasting to cover all of them with manual testing. So we give importance to automated UI Tests to verify that those scenarios are completed as intended.</p><h3>Why Do We Mock API Calls</h3><p>We realized that our UI Tests fail not only in our code changes but also in errors or unexpected responses in API calls. To eliminate API calls errors, we decided to mock API calls while executing our tests. Besides this, we realized UI Tests have many dependencies and their maintenance cost is high. So, we decided to mock API calls only for Smoke Tests. ( If you are not familiar with Smoke Tests concept, you can read <a href="https://medium.com/trendyol-tech/the-different-types-of-testing-on-trendyol-ios-app-f345124da2b3">Hazel Turan’s article</a>)</p><h3>Swifter Integration in Project</h3><p>There are different open-source projects to mock API calls. We decided to use Swifter because of its easy integration and ease of use. You can access a lot of information in <a href="https://medium.com/@Tovkal/mocking-network-calls-while-ui-testing-61e8a4a07f81">Andres Pisa’s article</a>.</p><p>Swifter, starts local server inside the app with default <strong>8080 </strong>port and it lets us to define which request call must return which JSON response.</p><p>We made some changes to start mocking API calls inside of the application while UI Tests are running.</p><p>If you want to access something inside the application during tests run, the only way is to use <strong>launchEnvironment </strong>and<strong> ProcessInfo</strong>. We add a variable to <strong>launchEnvironment </strong>before starting UI Tests<strong> </strong>and we get this variable inside the application with<strong> ProcessInfo.</strong></p><pre>launchEnvironment[&quot;MOCK_DATA_ENABLED&quot;] = &quot;1&quot;</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c6e25b9f5c0ff10f01c177be9ad9915/href">https://medium.com/media/7c6e25b9f5c0ff10f01c177be9ad9915/href</a></iframe><p>The most important part is to check the URL inside of the Network class. First of all, we need to guarantee that this control is not available for the Store scheme. Because, this scheme is for only App Store and we know that UI Tests will never run when this scheme is selected. After that, we control whether the <strong>ProcessInfo</strong> object has the key that must be added when only UI Tests running. If this key has value, then URL returns<strong> localhost:8080.</strong></p><p>We hold the JSON objects that we want to return from the local server as JSON files. To make an easy setup, we create a new JSON array file that includes every request’s URL, method and response’s JSON file name. With this way, when we need to add a new service request, all we have to do is to add this request’s URL , method and response’s JSON file name inside this JSON array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L0zEm-XWKNG0oQpzdCfsMg.png" /></figure><p>Before starting UI Tests, we read JSON array with the code below and for every object in this JSON array, we call <strong>setupStub </strong>function<strong>.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/83e890e4d1f294795bcee1cab4444e50/href">https://medium.com/media/83e890e4d1f294795bcee1cab4444e50/href</a></iframe><p>By using <strong>setupStub</strong> function, we kept the JSON response in the method choosen inside the local server.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/47e6fe1f665506fb84c399384deb108d/href">https://medium.com/media/47e6fe1f665506fb84c399384deb108d/href</a></iframe><p>We have different usages for different responses inside the same view. When we set service response, this response can only cover one usage. If we want to run UI Tests with a different response, then we should override same request with a different response after setup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f3RVZoO6GcvA4cfCVPunjA.png" /></figure><h4>Parallel Testing</h4><p>Running UI Tests sequentially takes a long time. To decrease test time, we enabled parallel testing option. This enabled us to start clone simulators at the same time and running tests in parallel but resulted in local server error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A3UOO_jvhOIXwdJIHMRxAg.png" /></figure><p>We realized that, this error was caused by the parallel testing. Each clone simulator tries to start local server with the same port (8080). To solve this problem, we made some changes in starting local server.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/34a08e961101e836c7799e99badb43d5/href">https://medium.com/media/34a08e961101e836c7799e99badb43d5/href</a></iframe><p>We started the local server with different port and we set port number to <strong>SERVER_PORT</strong> key in <strong>launchEnvironment </strong>to access inside the application.</p><pre>launchEnvironment[&quot;SERVER_PORT&quot;] = &quot;\(BaseTestHelper.shared.dynamicStubs.portNumber)/&quot;</pre><p>We accessed the port number in <strong>ProcessInfo.</strong></p><pre>ProcessInfo.processInfo.environment[&quot;SERVER_PORT&quot;] ?? &quot;8080/&quot;</pre><p>In conclusion, thanks to Swifter, we managed to run UI Tests with mock API calls. If you have any questions, do not hesitate to leave a comment below 🙂. Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b908dbf6b305" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trendyol-tech/mocking-api-calls-in-ui-tests-b908dbf6b305">Mocking API Calls in UI Tests</a> was originally published in <a href="https://medium.com/trendyol-tech">Trendyol Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrate Slather to Trendyol Project]]></title>
            <link>https://medium.com/trendyol-tech/integrate-slather-to-trendyol-project-39191cee7b7c?source=rss-a7d98cba1e38------2</link>
            <guid isPermaLink="false">https://medium.com/p/39191cee7b7c</guid>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[unittest]]></category>
            <dc:creator><![CDATA[Beyza Ince]]></dc:creator>
            <pubDate>Tue, 05 Jan 2021 11:26:01 GMT</pubDate>
            <atom:updated>2021-01-05T11:26:01.397Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U1-eXGAEHnTean8cD0MBEw.jpeg" /></figure><p>The dream of every software developer is to write Unit and UI tests and automate the whole building process.</p><p><strong>This dream becomes reality in Trendyol.</strong></p><p>Software development is a process in which change is inevitable. We run unit tests in Jenkins’s platform to make sure the implemented changes do not cause problems in the system and work as expected.</p><p>After the unit tests were successfully completed, we wanted to see the test coverage results. Even though Apple displayed results within the Xcode, they were too generalized. We needed focus on a more specified level, with possibly an extra feature. In the end, we came to the conclusion that Slather would be one of the best choices for our needs.</p><h4>Slather</h4><p>Slather <a href="https://github.com/SlatherOrg/slather">readme</a> file is very informative. We added Slather into the last step of Jenkins’s automation process. Jenkins is configured to run unit tests after opening a pull request or pushing a new commit into pr. If all tests are successfully completed, Slather starts to calculate test coverage. At the end of the process another automation tool, Skynet, sends Slack notification for test coverage results. You can read the details of automation bot process <a href="https://medium.com/trendyol-tech/the-effect-of-bots-on-automation-fb3135908632">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X66qp1m6DHeaT3faf-rv1A.png" /><figcaption>notification for test coverage result</figcaption></figure><h4>Integration</h4><p>We ran the following command line in the terminal to download Slather:</p><pre>gem install slather</pre><p>We activated the code coverage feature option to view the test results. This option is under the test section tab of the editing scheme. Otherwise, Slather cannot calculate coverage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*t9kjs6sXu26fI7koMwY6QQ.png" /><figcaption>enable code coverage option</figcaption></figure><h4>Create a Yml File</h4><p>Slather has a configuration file whose type is yml.<br>We divided our project into modules for an easy development process and decided to create a configuration file to cover different unit tests for each of the related modules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*rsSY_W9BNCoFMZIJa1Dc3g.png" /><figcaption>configuration files</figcaption></figure><p>We needed to move the configuration file to “.slather.yml” to be able to utilize these files.For instance, to use the “.Checkout-slather.yml” file, we ran the following command in the Jenkins pipeline script:</p><pre>sh &#39;mv .&#39; + testPlan + &#39;-slather.yml .slather.yml&#39;</pre><p>Each configuration file except the main one has different modules for calculating test coverage whereas the main one includes all modules. The main configuration file is executed after a new pull request is opened. When a new commit is pushed to pr, Slather executes the configuration file of this pull request’s modules. In this way, we achieved to reduce Slather’s running time for new commits. Well, how did we create and separate configuration files?</p><h4>Create Configuration File</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*kIXhisY_ygmQ0iJh3mh_ow.png" /><figcaption>configuration file example</figcaption></figure><p>As an example, let’s examine the above Slather file created for Checkout modules.</p><ul><li>We assigned to project’s xcodeproj and workspace names to the <strong>xcodeproj</strong> and <strong>workspace</strong> parameters as values. (Line 1–2)</li><li>We defined the type of <strong>scheme</strong> that runs the unit tests. (Line 3)</li><li>We defined the <strong>output_directory</strong> parameter value which Slather results will be added. (Line 4)</li><li>We added related modules under <strong>the binary_basename</strong> parameter. (Line 5- 10)</li><li>Unit tests are only written for the presenter classes in the project.We listed those class names under the <strong>ignore</strong> parameter to exclude other classes in the project from the test coverage (Line 11 -23).</li></ul><p>The command below must be executed to view Slather results in the local environment, after the unit test process is completed:</p><pre>slather coverage --show --html</pre><p>Afterwards, the test coverage results will be shown in the browser as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dLjNd4P2jAasZ4W29spGSg.png" /><figcaption>Slather result</figcaption></figure><p>We see this result thanks to Jenkins.</p><p>I tried to explain how to use Slather in our Jenkins process. I hope you enjoyed reading. If you have any questions, do not hesitate to leave a comment below 🙂. Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39191cee7b7c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trendyol-tech/integrate-slather-to-trendyol-project-39191cee7b7c">Integrate Slather to Trendyol Project</a> was originally published in <a href="https://medium.com/trendyol-tech">Trendyol Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>