Code Coverage

Code coverage tools allow us to discover which specific lines of code in the system were executed during a test. When you are starting to add tests to a legacy application, it can be really useful to know your code coverage:

  • If you know that a line of code isn’t covered by your tests yet, you can see more clearly what kind of a characterization test you need to write.

  • If you know that a line of code is covered by your tests, you can be more confident in refactoring or changing it.

There is no built-in support in Cucumber for collecting code coverage statistics. Instead, you need to install the SimpleCov[56] gem and add a couple of lines to your env.rb:

 require ​'simplecov'
 SimpleCov.start

When your features finish running, ...

Get The Cucumber Book, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.