Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Achieving peace of mind through test coverage

Ruy Adorno
October 08, 2019

Achieving peace of mind through test coverage

In this talk we are going to see how to efficiently implement tests in order to achieve a consistent and reliable release strategy that will allow all your team members to sleep at night.

Presented at http://js-montreal.org/ meetup of October 2019.

Git repo containing the demo presented can be find here: https://github.com/ruyadorno/the-one-with-test-coverage

Ruy Adorno

October 08, 2019
Tweet

More Decks by Ruy Adorno

Other Decks in Programming

Transcript

  1. Intro Tests are an essential tool that helps alleviate the

    task of maintaining a code base. They give us confidence when shipping new releases of a program by providing an automate assessment into its expected set of features. My hope with this talk is to enlighten on how coverage of code is important and provide practical tips on how to test more of your code.
  2. What is a test? • Program that runs your code

    • Validates your expectations • Makes sure things behave the way they should
  3. Benefits: • Reliability, you want to know about defects as

    soon as possible • Approachability, people can tweak your code and know if they break it • Quality, teams end up finding improvements and optimizations
  4. Coverage • Metric, it tracks what parts of your program

    actually executed • Doesn’t prove that the test suite is good • That can serve as a test itself
  5. Benefits: • In order to achieve higher coverage you have

    to dig deeper into the internals • Help to uncover bugs, serves as documentation to all program details • Serves as confidence meter for that code
  6. • Let’s go through some examples of helpful patterns while

    trying to bump test coverage Useful patterns:
  7. Snapshots • Useful when testing verbose output • pros: Extra

    convenient to work with • cons: requires way more discipline
  8. Mocking modules • Cleaner solution to checking to internal calls

    • Test frameworks tend to provide simpler to use APIs for those
  9. node-tap • Different test frameworks provide a different set of

    APIs but conceptually they all share the same ideas
  10. node-tap • One very convenient design choice of node-tap is

    allowing to run tests without the need of a top-level runner • Makes it so much easier to start debugging your tests
  11. It may be difficult to get coverage up, specially when

    reaching to parts of your codebase in which are harder to test by the very nature of the code there. I hope the patterns I share here help you on the task of covering more features of your code base using automated tests. Conclusion:
  12. Photo Credits • Photo by Kari Shea on Unsplash •

    Photo by Grzegorz Mleczek on Unsplash • Photo by rawpixel on Unsplash • Photo by Aidan Hancock on Unsplash