<?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 Michael Smykowski on Medium]]></title>
        <description><![CDATA[Stories by Michael Smykowski on Medium]]></description>
        <link>https://medium.com/@msmykowski?source=rss-3925b053e00a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2Jxoe3oyRJWeO5smZmIpxw.jpeg</url>
            <title>Stories by Michael Smykowski on Medium</title>
            <link>https://medium.com/@msmykowski?source=rss-3925b053e00a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 20:25:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@msmykowski/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[Elixir: Testing with Bypass]]></title>
            <link>https://medium.com/bleacher-report-engineering/elixir-testing-with-bypass-68a7f738db7a?source=rss-3925b053e00a------2</link>
            <guid isPermaLink="false">https://medium.com/p/68a7f738db7a</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[elixir]]></category>
            <dc:creator><![CDATA[Michael Smykowski]]></dc:creator>
            <pubDate>Fri, 07 Jul 2017 21:35:35 GMT</pubDate>
            <atom:updated>2017-07-10T19:53:14.551Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ldbVvKisFVwk6H2FlkHsNQ.jpeg" /><figcaption>Photo by <a href="https://www.flickr.com/photos/emeryway/3070695393/in/photolist-5Fm7L2-6iNGcK-aE3zwF-4mdRUA-riiKyx-aA4RwK-2aiX1x-qCvRC-BThbux-upwa7d-ivEFML-jvwdn-dBRbWS-3JPBmt-fjmJqH-cFNjgU-dBRbTG-p72Gyy-r2rp6S-iozqzT-FGSHJG-cM31L-T4uJSr-axnWc1-fjmBDp-fjASL5-FqVZ3A-FGSKBu-brS2TR-8AjC6M-FR3Gbr-EVN48x-FNKARL-FNKJNN-FKbKpg-34Rj6D-4RFJe1-FNKCef-aYimNr-EVB9Au-FGST4d-gQ2jTs-FKbM6T-9D7bkL-gQ2iF7-gQ2iuW-3b4CeN-5ifqXE-dHWQf7-axnUwA">Emery Way</a>. Used under the CC license.</figcaption></figure><p>Testing integration points in your application can be difficult and imperfect.</p><p>I have two main goals when testing integration points —</p><ol><li>Test that the correct request is made with associated path, body, headers etc.</li><li>Test the response and its expected transformation</li></ol><h3><strong>ExVCR</strong></h3><p><a href="https://github.com/parroty/exvcr">https://github.com/parroty/exvcr</a></p><p>ExVCR is a popular library that records initial HTTP responses in “cassettes”. Subsequent test runs will return these prerecorded responses for external HTTP requests.</p><p>Upside:</p><ul><li>ExVCR test setup is quick and easy.</li><li>Tests use real data (very useful for catching changes to response data structures)</li></ul><p>Downside:</p><ul><li>Cassettes must be updated frequently to prevent stale data</li><li>Upon updating cassettes, ephemeral data can lead to tedious test maintenance</li><li>Requests are environment specific</li><li>It is difficult to test connection properties (e.g., path, query, etc.) — because ExVCR does not give you access to the connection object, all assertions have to be made using the corresponding response</li></ul><h3>Bypass</h3><p><a href="https://github.com/PSPDFKit-labs/bypass">https://github.com/PSPDFKit-labs/bypass</a></p><p>Bypass takes a very different approach to testing HTTP requests. Bypass spins up a local server that intercepts outgoing requests. Assertions can be made on the intercepted request connection, and a manually constructed response can be sent back.</p><p>Upside:</p><ul><li>Tests written with Bypass are not environment specific and do not require internet to pass (tests work out of the box)</li><li>Asserting on the connection object is easy and intuitive</li><li>Response data values are predictable, tests are more robust</li></ul><p>Downside:</p><ul><li>Test setup with Bypass is a manual process. A local Bypass server needs to be initialized for every external service to be <em>bypassed</em>. Responses need to be constructed by hand</li><li>Response data is not real. The developer must be aware of response data structure changes, and update the test accordingly</li></ul><p>Bypass is a great solution for testing integration points, however the test setup can be tedious and redundant.</p><p>Here is an example test using Bypass:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OZoHnDXkKHRqOCYFDMNGMA.png" /></figure><p>Alone, one test does not look to0 bad, but a file full of Bypass tests can become an eyesore full of duplicate code and repeat assertions.</p><h3><strong>ExUnit Tags to the Rescue</strong></h3><p>ExUnit tags are a great way to organize tests and provide custom test setups. Tags can be accessed via ExUnit’s context, where they can be used in callbacks to tailor individual tests.</p><p>Using tags, we can rewrite the previous test as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D_LLKcOuEbIPKzIhk4niFA.png" /><figcaption>service_one_controller_test.exs</figcaption></figure><p>The test is tagged with the ExUnit tag “service_one”. The presence of this tag is responsible for initializing a Bypass server for that particular service. The map of values will be used to make assertions and return a response from the Bypass server.</p><p>Internally, here is what is happening —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*s6z6_0TPHSlHDgQlCRfoDA.png" /><figcaption>conn_case.ex</figcaption></figure><p>We have defined a list of Bypass tags. The key corresponds to the service-specific ExUnit tag to be used when initializing a Bypass server, while the value corresponds to the system configuration environment variable to be pointed towards the Bypass server (this setup works for initializing multiple Bypass servers).</p><p>In our setup we have access to the ExUnit tags for the current test being run. When one of these tags matches a defined Bypass tag, we pass those values to our Bypass module.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0CICjuJuiMsBiQIByin0yA.png" /><figcaption>bypass.ex</figcaption></figure><p>Our Bypass module initializes a Bypass server, and points the system configuration to the local Bypass server. The on_exit callback is used to restore this configuration once the test has ended. This will be done for each service with a corresponding ExUnit tag present.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XJwmloecMHFYRf2QVbSHLQ.png" /><figcaption>bypass.ex</figcaption></figure><p>The Bypass module also handles the assertions for the specific test, asserting on all relevant parameters provided via the ExUnit tag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FPPK6758MJ-RpMgS5tGNtA.png" /><figcaption>bypass.ex</figcaption></figure><p>Furthermore, the Bypass module will return a predefined status code and response from the Bypass server (using the parameters provided or a default).</p><p>All of our Bypass setup and assertion code is consolidated into a single module, which DRY’s our tests significantly.</p><p>Additionally, our tests are now documenting external requests. The properties of our external requests are listed in a readable map, rather than jumbled within the code.</p><p>Of course there are times where this setup can be restrictive. For these cases, the Bypass object is still returned in the test context to be used as needed in the test itself.</p><p>This is one solution I have found works well when testing integration points. Feedback and improvements would be greatly appreciated!</p><p>More of the code, examples, and documentation can be found at: <a href="https://github.com/msmykowski/double_bypass">https://github.com/msmykowski/double_bypass</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68a7f738db7a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bleacher-report-engineering/elixir-testing-with-bypass-68a7f738db7a">Elixir: Testing with Bypass</a> was originally published in <a href="https://medium.com/bleacher-report-engineering">Bleacher Report Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>