Slide 1

Slide 1 text

Achieving peace of mind through test coverage js-montreal 10/2019

Slide 2

Slide 2 text

Ruy Adorno @ruyadorno OSS Dev @

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

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.

Slide 5

Slide 5 text

What is a test? • Program that runs your code • Validates your expectations • Makes sure things behave the way they should

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

Mergebot • Github bot • Controls merging PRs • Front End cli scripts

Slide 10

Slide 10 text

• Let’s go through some examples of helpful patterns while trying to bump test coverage Useful patterns:

Slide 11

Slide 11 text

Snapshots

Slide 12

Slide 12 text

Snapshots • Useful when testing verbose output • pros: Extra convenient to work with • cons: requires way more discipline

Slide 13

Slide 13 text

Patch APIs

Slide 14

Slide 14 text

Patch APIs • Allow us to assert for specific internal calls (specially global)

Slide 15

Slide 15 text

Abstractions

Slide 16

Slide 16 text

Abstractions • Abstract hard to test internals into separated function/modules

Slide 17

Slide 17 text

Mocking modules

Slide 18

Slide 18 text

Mocking modules • Cleaner solution to checking to internal calls • Test frameworks tend to provide simpler to use APIs for those

Slide 19

Slide 19 text

node-tap

Slide 20

Slide 20 text

node-tap • Different test frameworks provide a different set of APIs but conceptually they all share the same ideas

Slide 21

Slide 21 text

node-tap

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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:

Slide 24

Slide 24 text

process.exit(0) https://ruyadorno.com Thanks!

Slide 25

Slide 25 text

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