<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Oscar Antonio Duran Grillo</title>
    <description>The latest articles on DEV Community by Oscar Antonio Duran Grillo (@skyweb07).</description>
    <link>https://dev.to/skyweb07</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F5445%2F747750.jpeg</url>
      <title>DEV Community: Oscar Antonio Duran Grillo</title>
      <link>https://dev.to/skyweb07</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/skyweb07"/>
    <language>en</language>
    <item>
      <title>An intro to Snapshot testing 📸 </title>
      <dc:creator>Oscar Antonio Duran Grillo</dc:creator>
      <pubDate>Sat, 25 Nov 2017 18:32:30 +0000</pubDate>
      <link>https://dev.to/skyweb07/an-intro-to-snapshot-testing--ke</link>
      <guid>https://dev.to/skyweb07/an-intro-to-snapshot-testing--ke</guid>
      <description>&lt;p&gt;So, I’m in the way of making a new app and I would love to share all my learnings while I’m in the progress so I can keep my self-motivated and share some knowledge that hopefully, you can use for your owns apps.&lt;/p&gt;

&lt;h3&gt;
  
  
  🎨 Why to test the UI?
&lt;/h3&gt;

&lt;p&gt;You want to make sure that every time you touch any of your UI elements everything stays as they way they were meant to be, also this kind of integration test help you achieve the pixel perfect views and make your designers happy by having design reference images that they can see even in your pull requests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--40MCPO7n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2A_Kt6ULxjNjf8wVv3l9dzrg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--40MCPO7n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1600/1%2A_Kt6ULxjNjf8wVv3l9dzrg.jpeg" alt=""&gt;&lt;/a&gt;&lt;br&gt;
So you want to achieve pixel-perfect while making some nice tests?&lt;/p&gt;
&lt;h3&gt;
  
  
  ⚡️ How does it work?
&lt;/h3&gt;

&lt;p&gt;I'll try to describe how to use this method using my latest lib &lt;a href="https://github.com/skyweb07/Snap.swift"&gt;Snap.swift&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It works by generating a reference image that gets stored in your repository and then comparing each new test case with the &lt;code&gt;reference image&lt;/code&gt; to check if there are any differences. If test found any differences it will add an attachment into your test case and you'll be able to check what changed&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fKSWNNDp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/skyweb07/Snap.swift/blob/develop/.art/xcode_attachment.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fKSWNNDp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/skyweb07/Snap.swift/blob/develop/.art/xcode_attachment.png%3Fraw%3Dtrue" alt="Project attachment"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  🛠 Configuration
&lt;/h3&gt;

&lt;p&gt;In order to configure the snapshot test folder, we need to add a new environment variable to the project with name &lt;code&gt;SNAP_REFERENCE_IMAGE_PATH&lt;/code&gt; and value &lt;code&gt;$(SOURCE_ROOT)/$(PROJECT_NAME)Tests/&lt;/code&gt; so &lt;code&gt;Snap.swift&lt;/code&gt; can find the folder to store the reference images. If the configuration was correctly set the project should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GJSLow3n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/skyweb07/Snap.swift/blob/develop/.art/xcode_project_environment_variable.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GJSLow3n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/skyweb07/Snap.swift/blob/develop/.art/xcode_project_environment_variable.png%3Fraw%3Dtrue" alt="Project attachment"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  🎯 Installation
&lt;/h3&gt;

&lt;p&gt;Snap.swift is available through &lt;a href="http://cocoapods.org"&gt;CocoaPods&lt;/a&gt;. To install&lt;br&gt;
it, simply add the following line to your Podfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;pod&lt;/span&gt; &lt;span class="s1"&gt;'Snap.swift'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ✅ Creating our first test
&lt;/h3&gt;

&lt;p&gt;1) We first need to record our reference images, in order to do so we have to first go into our test class and set the &lt;code&gt;isRecording&lt;/code&gt; variable to be &lt;code&gt;true&lt;/code&gt; so the library knows that we are in record mode and can extract the &lt;code&gt;reference images&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;import&lt;/span&gt; &lt;span class="kt"&gt;XCTest&lt;/span&gt;
&lt;span class="kd"&gt;import&lt;/span&gt; &lt;span class="kt"&gt;Snap_swift&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="kt"&gt;SnapTests&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;XCTestCase&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;setUp&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setUp&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;isRecording&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;test_box_with_text_aligned_to_center&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;view&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;BoxWithTextAlignedToCenterView&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;view&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toMatchSnapshot&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After executing out test suite if everything was ok we should see that all of our tests failed with a warning similar to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;⚠️ Test ran &lt;span class="k"&gt;in &lt;/span&gt;record mode, reference image has been saved to &lt;span class="nv"&gt;$SNAP_REFERENCE_IMAGE_PATH&lt;/span&gt;/testcase.png, now remove &lt;span class="sb"&gt;`&lt;/span&gt;isRecording&lt;span class="sb"&gt;`&lt;/span&gt; &lt;span class="k"&gt;in &lt;/span&gt;order to perform the snapshot comparison.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is ok, it just means that our reference images were saved, we can inspect them in our &lt;code&gt;reference image&lt;/code&gt; directory, we should normally add these into &lt;code&gt;git&lt;/code&gt;  so we can compare against them. &lt;/p&gt;

&lt;h4&gt;
  
  
  ⚠️ Warning
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Remember to remove the &lt;code&gt;isRecording&lt;/code&gt; flag after generating your reference images or you won't be able to do the image comparison&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  📝 Notes
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;As today, you can make assertions on &lt;code&gt;UIView&lt;/code&gt; and &lt;code&gt;CALayer&lt;/code&gt; classes.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The project is highly inspired on &lt;code&gt;Facebook&lt;/code&gt; &lt;a href="https://github.com/facebookarchive/ios-snapshot-test-case/"&gt;FBSnapshotTestCase&lt;/a&gt; library, it seems that they had archived the library so I started this one to continue envolving the project and continue with mobile &lt;code&gt;snapshot-testing&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;There are other ways to test UI elements by using libs like KIF or EarlGrey by Google but I think this kind of snapshot test are more easy to maintain and one of the Snap.tests could be equal to many of the other frameworks.&lt;br&gt;
If you have any doubts or questions you can reach me via &lt;a href="https://twitter.com/skyweb07"&gt;Twitter&lt;/a&gt; and I’ll try to help you out.  &lt;/p&gt;

&lt;p&gt;Thanks you all and happy Snapshot testing 📸&lt;/p&gt;

</description>
      <category>swift</category>
      <category>testing</category>
      <category>showdev</category>
      <category>xcode</category>
    </item>
    <item>
      <title>Hi, I'm Oscar Antonio Duran Grillo</title>
      <dc:creator>Oscar Antonio Duran Grillo</dc:creator>
      <pubDate>Wed, 22 Feb 2017 18:53:14 +0000</pubDate>
      <link>https://dev.to/skyweb07/hi-im-oscar-antonio-duran-grillo</link>
      <guid>https://dev.to/skyweb07/hi-im-oscar-antonio-duran-grillo</guid>
      <description>&lt;p&gt;I have been coding for 7 years.&lt;/p&gt;

&lt;p&gt;You can find me on GitHub as &lt;a href="https://github.com/skyweb07" rel="noopener noreferrer"&gt;skyweb07&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I live in Barcelona.&lt;/p&gt;

&lt;p&gt;I work for Wallapop&lt;/p&gt;

&lt;p&gt;I mostly program in these languages: Swift, Objective-C, PHP, Java.&lt;/p&gt;

&lt;p&gt;I am currently learning more about Big Data, IA.&lt;/p&gt;

&lt;p&gt;Nice to meet you.&lt;/p&gt;

</description>
      <category>introduction</category>
    </item>
  </channel>
</rss>
