Posts

Showing posts from January, 2019

100% Test Coverage?

When you write unit tests, do you try to achieve 100% test coverage or are you content with anything above 80% test coverage? Most of the time, I feel that trying to achieve 100% test coverage is a waste of time. The return of investment starts to diminish once the coverage goes above 80%. However, what happens today make me reconsider the benefits of trying to achieve 100% test coverage. This was the original code: 10 function isFullyCheckedBy (type, data) { 11 const { entries = [] } = data 12 13 for (const entry of entries) { 14 const { results = {} } = entry 15 if (results[type] !== true) { 16 return false 17 } 18 } 19 return true 20 } 21 The coverage tool complained that "line 11" was not covered. My initial reaction was, "does it matter?". Anyhow, I tried to write a test to create a scenario to trigger the default assignment in "line 11". After running the new test, I was surprised to find out that "isFullyCheckedB