The failed promise of testing

Let’s start with a simple question: Why do we need tests? We could point out 2 reasons:

  1. fewer bugs on production
  2. safety when refactoring

1. safety while coding

But the truth is, we’re writing tests to make sure that “it works correctly for given scenarios”. We can hardly ever write tests with all the possible inputs and all possible states of our internal data (we might, but try to keep up with thousands of tests…).

What we could strive for, is to test the most important business requirements + making sure we cover the most probable bad cases.

Make sure to test parts of the system, where fixes involve a big effort (like bad state in the DB, etc). [[ TODO]]

2. safety while refactoring

Second reason is refactoring - changing code’s structure without changing its functionality.

How often do you hear that?

implementing this feature will take very long, because we’ll need to do a lot of testing

or

we could refactor this module and then this feature would be easy to implement, but testing will take too much time.

Let’s ask an honest question - how often your tests fail when you refactor your code? And what is your confidence that new changes don’t introduce bugs?

Often if tests go 🔴, is it because we’ve introduced a bug while refactoring? Or maybe our tests were simply not flexible enough to handle the change.

And then if tests go 🟢, is it because we’ve correctly adjusted the tests to match code’s behaviour? Or did we make them pass by accident?

Immutestable - why?

Immutestable is a set of patterns and practices to test your code, that make your tests:

  • that go 🔴 when you actually introduce a bug
  • easy to write
  • helps you to deliver code with maximum confidence
  • help you to design your API better

What’s the end goal with tests? It’s a moment when you trust your tests so that you can deploy your code without any manual tests.

And why not only you but also your business would benefit? Because it’s faster, cheaper, and more reliable (customer satisfaction) to fulfill changing requirements. 🐇

Let’s jump into 3 principles of Immutestable that are the basics for everything that follows, and let’s see how good practices for tests can help you to achieve the goal.

Other sources: