Posts

Showing posts from September, 2019

100% code coverage is false safety

Image
It is really easy to lie to yourself when doing Test Driven Development that your code is good, safe, predictable and well understood, just because you have that magic 100% code coverage number. If you test just the happy case it is easy to get to 100% code coverage, while still leaving code paths untested and unexpected behaviour unexplored. Consider this simple function that takes in an object with 2 properties, an array of strings and a separating string to concatenate between them. 1: export const concatStrings = ({ strings, joiner }) => { 2: return strings.join(joiner); 3: }; Testing the Happy Path is really easy. 1: import { concatStrings } from "./stringConcat"; 2: describe(concatStrings, () => { 3: it("Should concatinate strings", () => { 4: const actual = concatStrings({ joiner: ", ", strings: ["one", "two"] }); 5: expect(actual).toBe("one, two"); 6: });