Thursday, July 16, 2020

Unit Testing is Overrated

I have found  very good article about testing:

Unit Testing is Overrated

Here are the main takeaways:

  1. Think critically and challenge best practices
  2. Don't rely on the the test pyramid
  3. Separate tests by functionality, rather than by classes, modules, or scope
  4. Aim for the highest level of integration while maintaining reasonable speed and cost
  5. Avoid sacrificing software design for testability
  6. Consider mocking only as a last resort

I have two notes:
  1. Relying on acual GeoIP provider - I'd fake it for PR gates because we don't want to block our PRs when the provider has an outage. I keep using it for CD gates.
  2. Caching test is not sufficient - I'd add assert the cache contains tested record.

The article links another good posts:
  • Write tests. Not too many. Mostly integration. - The Testing Trophy
    It doesn't matter if your component renders component b with props c and d if component b actually breaks if prop e is not supplied. So while having some unit tests to verify these pieces work in isolation isn't a bad thing, it doesn't do you any good if you don't also verify that they work together properly. And you'll find that by testing that they work together properly, you often don't need to bother testing them in isolation.
  • Testing of Microservices - integration test is the king