The Way to Testing Mastery, Part 3: Revolutions

The How: Going Down the Rabbit Hole

Jessie Hernandez
Geek Culture

--

Now comes the least important part of this article, but the most anticipated by developers: the technical aspects of high test coverage which equate to high code quality. If all you want to know is how to increase your test coverage numbers to look good or to impress your boss, then stop reading, step away from the keyboard and find a job in another industry. High test coverage should be a natural byproduct of increasing your code quality and the quality of your tests. Code coverage reports should be inspected only at the very end of your test-writing process. Uncovered lines of code in a code coverage report indicate which scenarios have not yet been tested.

I suggest you do TDD/BDD when you’re starting off writing testable code. Only when you’re seriously proficient may you write the code first and the tests later. This is because you already know how to write testable code and are already thinking of the types of tests you need to write while you’re writing the code.

We’ll start with a simple use-case: a user preferences services. We’ll design this service with 3 code layers:

handler/controller → service → repository → database

--

--