Writing Clear Tests

A very rudimentary but fundamental tip: When you are testing something, it is absolutely paramount that you have a crystal clear idea in your mind of exactly what you are testing.

If you want to ensure that there are 4 tyres on your car, before you start out from your garage, you must check for exactly that:

  • are there four tyres on my car?

If you test for something else:

  • are there tyres on my car?

Then you may win some of the time, but other times you will get confusing and conflicting results.  What if somebody adds 3 tyres, but omits one tyre? Obviously this car will have a lot of problems going forward (pun intended), and you will wonder why all of a sudden your tests are all passing but the car is failing?

What is going on? And it will not be immediately obvious what is going on. Because the mind can deceive, and while the eyes see, they may yet be blind. You’ll be spending a loooooooooooot of time trying to debug that one little glitch. Save yourself the headache, especially if you’re looking at the code 6 months later.

 

So it is a very simple, but very powerful tip:

  • be very specific and clear in your mind as to exactly what you are testing for.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *