Do you write tests for everything?

Do you write tests for everything?

How about if I tell you, Test Driven Development isn’t about testing your code. It’s about designing.

I’m not kidding! When you are writing tests, it forces you to think about what kind of interface do you need and how it is supposed to work.

If something can go wrong, it will!
Certainly, every developer goes through this and tests help to save you from this. Recently, a term has been introduced, Shift-left testing which basically means shifting testing in the development phase, so that lesser time is spent during extensive testing. But, do you test everything?

Test only what can possibly break
Testing everything means testing each line of your code, but testing what can break means testing different combinations of inputs to check where something goes wrong.

There’s no point in testing those pieces of code which:

  1. Frameworks:
    $a = 2;
  2. Have no logic:
    public function a() { return 2; }

So, how do you find what to test?
You can determine what to test by 3 simple rules. The problem you want to test should be :

  1. Repeatable
    You’re testing that test case every time for your product.
  2. Unopinionated:
    The result is based on only logic, not on emotions or any kind of story.
  3. Deterministic:
    There needs to be some specific input and expected output to be tested.

Testing changes the way you develop by setting a legacy of your code design. Keep testing and keep improving!

Subscribe to Haox

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe