re: What I've Learned About Testing React Apps - Part 1: Unit Tests VIEW POST


I would add two things to the reason we're unit testing, which may tip you towards getting that 100% coverage after all.

  1. Unit tests indicate brittle code. Ever wrote a unit test that was a pain to set up? That's a pretty good clue that your code is doing too much and/or is poorly organised. This is your chance to change that, and rejig your code until it is easy to unit test.
  2. Unit tests are part of the documentation. Imagine you've landed on an alien codebase and while trawling through the code, you come across something odd. Is this a bug or is it a feature? The official documentation is silent about the matter but maybe they just forgot to write it down? Well, head over to the unit tests then...oh, there aren't any. Now you've got a problem.

So to sum it up, unit tests are about a lot more than just double-checking X really does Y. That is not to say you should chase 100% coverage at all costs or by any means, of course you shouldn't. We all know that will end up with tests that mean nothing. But you better be clear about why you leave out bits and "that bit's difficult to test" is usually not a good excuse.

code of conduct - report abuse