1
0 Comments

Do you hate unit tests?

Tests test your COMMON SENSE.

We want our code to WORK.

We want it to KEEP WORKING.

We want to develop FAST with CONFIDENCE.

Here's how:

1/ Each unit should test ONE THING.

2/ Make it FAIL before you make it pass.

3/ Write tests with KNOWN OUTPUT.

Like √4 instead of √2.

4/ Write tests with KNOWN INPUT.

Don't use named constants from the model code.

Avoid generating random input.

Use literal strings and fixed values.

It's ugly but safe.

5/ Don't touch the scary outside world.

Mock network calls, local file access, your girlfriend, etc.


Follow these principles and testing will suck slightly less.

on July 24, 2022