<?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: Dylan Broadbridge</title>
    <description>The latest articles on DEV Community by Dylan Broadbridge (@d_broadbridge).</description>
    <link>https://dev.to/d_broadbridge</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%2F153359%2Fb893a4a2-4dc5-4b75-a1c6-f76499de1d5d.jpg</url>
      <title>DEV Community: Dylan Broadbridge</title>
      <link>https://dev.to/d_broadbridge</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/d_broadbridge"/>
    <language>en</language>
    <item>
      <title>Kick-start a Testing Strategy</title>
      <dc:creator>Dylan Broadbridge</dc:creator>
      <pubDate>Tue, 16 Apr 2019 10:28:33 +0000</pubDate>
      <link>https://dev.to/d_broadbridge/kick-start-a-testing-strategy-3ok9</link>
      <guid>https://dev.to/d_broadbridge/kick-start-a-testing-strategy-3ok9</guid>
      <description>&lt;p&gt;A common hurdle I see among developers is deciding on a testing strategy for the system they are working on.&lt;/p&gt;

&lt;p&gt;Thankfully finding a good testing strategy involves the entire team, not just developers as it is everyone's responsibility that the system works as intended.&lt;/p&gt;

&lt;h3&gt;
  
  
  Kick it off
&lt;/h3&gt;

&lt;p&gt;Gather everyone who has a stake in your technology together for a meeting, the purpose of which is to discover and understand the risks involved in your technology operations.&lt;/p&gt;

&lt;p&gt;Get everyone to list off features of your technology onto post it notes, the more diverse the people present the more features you will discover as certain features are more relevant to different areas.&lt;/p&gt;

&lt;p&gt;Once you have a list of features, draw the following chart on a whiteboard.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6-ypO56C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/pqj0boj3p94h2i6yltcj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6-ypO56C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/pqj0boj3p94h2i6yltcj.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Get everyone to place the features where they think is appropriate. Since I have some experience in insurance I will use that as an example.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--D58mFLha--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/iabpkftrmedg5w69jibm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D58mFLha--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/iabpkftrmedg5w69jibm.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here I have four features;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User can submit a claim: Users rarely submit claims and are able to call us if there is an issue with the online system.&lt;/li&gt;
&lt;li&gt;User can buy a policy: Need this to make money but a user will only ever do it once and it is not the end of the world if it malfunctions.&lt;/li&gt;
&lt;li&gt;User can be declined: Every user will interact with this feature before buying a policy, and the cost to the business for one malfunction of this feature can be catastrophic to the business.&lt;/li&gt;
&lt;li&gt;User gets the correct price: Users need to get quotes that are reasonably priced, but this feature is about getting an accurate price which doesn't carry as much risk as a decline.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once the features are understood by everyone draw two or more lines from top left to bottom right. These define how much risk it is to the business if something goes wrong with a feature.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yZvRia6s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/4k4h7ixo1nsfi2kk2sid.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yZvRia6s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/4k4h7ixo1nsfi2kk2sid.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once everyone has agreed on where features sit within the zones, conclude the meeting.&lt;/p&gt;

&lt;h3&gt;
  
  
  Develop and Communicate the Technical Implementation
&lt;/h3&gt;

&lt;p&gt;Gather all technical staff and develop a rough guide to testing different parts of the system based on the risk (risk-based testing). Following on from the previous example you may end up with something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NOaNGcWT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/shxfs3uxrck7gipubv57.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NOaNGcWT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/shxfs3uxrck7gipubv57.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to have additional rows like trivial and critical to better classify the varying risks in your business.&lt;/p&gt;

&lt;p&gt;In the example we have extra monitoring for success on the declines to let us know that the service was functioning as expected. We also manually test that the service was working before each release on pre-production to be 100% sure it is working before releasing.&lt;/p&gt;

&lt;p&gt;Once the technical team has decided on a rough testing strategy they can present back to the rest of the team. Developers should take onboard any feedback and adapt.&lt;/p&gt;

&lt;h3&gt;
  
  
  Learn and Improve
&lt;/h3&gt;

&lt;p&gt;It is highly unlikely the strategy is perfect and it is important to keep improving. &lt;/p&gt;

&lt;p&gt;A couple ideas to improve your testing strategy are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Whenever there is a bug in production assess its impact and if its significant adjust your testing strategy to prevent it from happening again.&lt;/li&gt;
&lt;li&gt;Set metrics to measure the outcome of your testing strategies, an interesting metric I've heard of is escape defects which are issues in production that were not identified before reaching customers. If you are able to measure something like that accurately and weigh it by impact of the defect it can provide insight into how your testing is performing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks for reading. &lt;/p&gt;

&lt;p&gt;Inspired by:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=RuGFSSUYGXQ"&gt;https://www.youtube.com/watch?v=RuGFSSUYGXQ&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=rSY-zqDfc_s"&gt;https://www.youtube.com/watch?v=rSY-zqDfc_s&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Reviewed by: @nhnhatquan, @WickyNilliams&lt;/p&gt;

</description>
      <category>testing</category>
      <category>agile</category>
    </item>
    <item>
      <title>You Might Not Need Integration Tests</title>
      <dc:creator>Dylan Broadbridge</dc:creator>
      <pubDate>Sun, 07 Apr 2019 08:22:50 +0000</pubDate>
      <link>https://dev.to/d_broadbridge/you-might-not-need-integration-tests-14a8</link>
      <guid>https://dev.to/d_broadbridge/you-might-not-need-integration-tests-14a8</guid>
      <description>&lt;p&gt;NOTE: This is an advanced topic and assumes knowledge of CI/CD, integration testing, types and a bit of devOps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I questioned the existence of integration tests
&lt;/h2&gt;

&lt;p&gt;Ah the classic integration test, giving you confidence that all the parts of your app work together in a way unit tests never can. They can take a long time to run and require complex tooling like localstack (in the case of AWS), but that doesn't matter right? All good things take time and the confidence of everything going green is worth it.&lt;/p&gt;

&lt;p&gt;Maybe Not.&lt;/p&gt;

&lt;p&gt;My idea on testing was challenged when I read this tweet:&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1110021204272971776-860" src="https://platform.twitter.com/embed/Tweet.html?id=1110021204272971776"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1110021204272971776-860');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1110021204272971776&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;What is going on here? Are my integration tests a waste of time???&lt;/p&gt;

&lt;h2&gt;
  
  
  How did we get here?
&lt;/h2&gt;

&lt;p&gt;After having a good think for few days I finally understood the simple idea behind Brian's tweet:&lt;/p&gt;

&lt;p&gt;Your testing strategy should include your operational strategy.&lt;/p&gt;

&lt;p&gt;I had failed to take into account how operations could affect my testing, it was a shock and when I rounded up my fellow engineers it turns out none of them had either.&lt;/p&gt;

&lt;p&gt;But why does it matter? Ops is Ops and testing is testing surely they have minimal impact on each other? Right?&lt;/p&gt;

&lt;p&gt;Nope.&lt;/p&gt;

&lt;p&gt;The success of your application is dependent not only on what you do in code and how it runs on your machine but also how it will work in production.&lt;/p&gt;

&lt;p&gt;Testing strategies have remained solid for decades now, integration tests have existed since the dawn of programming and still continue to be useful. But Ops has been evolving, ideas like CI/CD have only recently taken off and not taking advantage of modern Ops would be a mistake when deciding on a testing strategy.&lt;/p&gt;

&lt;h2&gt;
  
  
  So what do we do?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Canary Deployments
&lt;/h3&gt;

&lt;p&gt; ... Prefer to invest in monitoring (and partial rollouts/rollbacks) when possible. - Brian&lt;/p&gt;

&lt;p&gt;Modern Ops tooling gives you the option of doing canary releases which is an extension of red green deployments where you always deploy your changes onto a new server.&lt;/p&gt;

&lt;p&gt;Canary deployments divert a small % (usually 10%) of users for a small amount of time (usually 15-60 min) to the new deployment.&lt;/p&gt;

&lt;p&gt;During this switch your deployment service is receiving events from your monitoring tools and will "cancel" the switch if an error event is seen and all users will continue to use the currently deployed application.&lt;/p&gt;

&lt;p&gt;It can be difficult to setup but luckily managed services like AWS give you canary deployments for free and can generally be configured in less than a day. &lt;/p&gt;

&lt;p&gt;The result of canary deployments is that any issues with the new deployment are contained to only a few users with automatic rollback preventing any extra damage.&lt;/p&gt;

&lt;p&gt;The cost of making mistakes in production has been greatly reduced with tools like canary deployments.&lt;/p&gt;

&lt;h3&gt;
  
  
  Type to safety
&lt;/h3&gt;

&lt;p&gt;So making a mistake in production is much less of an issue than it used to be, but still how do you know your code works if you aren't writing any integration tests? &lt;/p&gt;

&lt;p&gt;Types. If it compiles it works.&lt;/p&gt;

&lt;p&gt;Let's look at some common examples of integrations and how types are able to give us enough confidence that our code will work in production.&lt;/p&gt;

&lt;p&gt;&lt;b&gt; 3rd Party Api's &lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Chances are these APIs come with SDK's that are fully typed, meaning that if you give the right input and it passes type checking then it is safe to assume that it works. &lt;/p&gt;

&lt;p&gt;There is actually nothing to test, you have called the SDK correctly and the rest is up to the 3rd party provider.&lt;/p&gt;

&lt;p&gt;The response will also be typed so you know the exact shape of data that you get back from the API. If you try to use this data incorrectly you will have a compile time error. &lt;/p&gt;

&lt;p&gt;&lt;b&gt; Database interactions &lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Assuming your database methods are fully typed and tested in an internal or external module you should have no trouble just using the methods and types provided by that module. &lt;/p&gt;

&lt;p&gt;If your database requires certain data to create a record then your types will catch that. If you can only update certain fields your types will catch that. If you are using the response from the database to do some logic and you are missing some data the types will also catch that. &lt;/p&gt;

&lt;p&gt;I would say that for almost every database interaction besides complex data migrations and table creation types are more than sufficient to have confidence that it will work in production.&lt;/p&gt;

&lt;p&gt;&lt;b&gt; What about stuff that isn't CRUD? &lt;/b&gt;&lt;/p&gt;

&lt;p&gt;So from above you end up with 0 unit and integration tests for CRUD and basic API usage. But what about business logic?&lt;/p&gt;

&lt;p&gt;...Testing of functions pays for itself (when using property testing and no mocks)... - Brian&lt;/p&gt;

&lt;p&gt;You should be able to write your business logic as functions that you can test separately without the need to mock anything.&lt;/p&gt;

&lt;p&gt;Doing this you get access to more advanced testing options like property testing where you can generate a wide range of inputs (usually 100) and check that your business logic handles them in a fraction of a second. Your tests will alert you to any edge cases that you may have missed in your code providing extra value to traditional deep assertion unit tests. (I recommend a combination of both)&lt;/p&gt;

&lt;h3&gt;
  
  
  Why does this matter? Integration tests have worked for decades why should we change?
&lt;/h3&gt;

&lt;p&gt;Think of it like this, you either spend time writing integration tests and running them on every deployment or just skip them and rely on your Ops and types. &lt;/p&gt;

&lt;p&gt;There is a point where the time spent fixing that one prod error that occasionally makes it through is less than adding on 40, 60, 90+ minutes of waiting for your &lt;br&gt;
integration tests to run before going to production on each commit.&lt;/p&gt;

&lt;p&gt;Lets do some Math:&lt;/p&gt;

&lt;p&gt;Traditional Workflow per commit:&lt;/p&gt;

&lt;p&gt;Write code (10 min)&lt;br&gt;
Write unit tests (10 min)&lt;br&gt;
Write integration tests (10 min)&lt;/p&gt;

&lt;p&gt;Deploy to a test environment (5 min)&lt;br&gt;
Run your integration test (2N min)&lt;/p&gt;

&lt;p&gt;Deploy to production (5 min)&lt;/p&gt;

&lt;p&gt;Total: 40 + 2N mins per commit&lt;/p&gt;

&lt;p&gt;My Suggested Workflow:&lt;/p&gt;

&lt;p&gt;Write code (10 min)&lt;br&gt;
Write unit and generative tests (15 min) (extra value here)&lt;/p&gt;

&lt;p&gt;Deploy to production (5 min)&lt;/p&gt;

&lt;p&gt;Total: 25 mins per commit&lt;/p&gt;

&lt;p&gt;Let's say you end up with 100 commits, that would take 2,500 mins to develop without integration tests compared to a whopping 14,000 mins using integration tests. That's a factor of 5.6x.&lt;/p&gt;

&lt;p&gt;Is the extra fraction of a % more confidence worth losing out on 5.6x speed? &lt;/p&gt;

&lt;p&gt;Integration tests can also be difficult to setup and maintain, time that could be better spent on better monitoring in production. &lt;/p&gt;

&lt;p&gt;Integration tests are still useful and maybe occasionally necessary, but consider their use carefully because you might not need integration testing for your webapp.&lt;/p&gt;

&lt;p&gt;Thanks for reading,&lt;/p&gt;

&lt;p&gt;Please feel free to comment, tweet or DM me with any thoughts or questions.&lt;/p&gt;

&lt;p&gt;Thanks to &lt;a class="mentioned-user" href="https://dev.to/paulgrizzay"&gt;@paulgrizzay&lt;/a&gt;, @someivorytower, @nhnhatquan, @puffnfresh and others for reviewing.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>advanced</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
