A buddy of mine decided to finally give testing a try (not true TDD, but still writing tests) and he made me laugh by some of the statements/observations he made.
- Where do I start?
- This feels weird!
- Am I doing this right?
- How much is enough?
When he mentioned these to me I had to laugh. Why, not because I was making fun of him, but because I remember having these exact same feelings when I started testing.
For anyone else having these feelings, here is my personal advice.
Where do I start?
Start where you are comfortable. Pick a place where you know the code and add a few tests. Make your initial tests small, but productive. Don't start out by trying to follow full blown TDD (let the flames begin) as it will just lead to more confusion.
This feels weird!
This means you are out of your comfort zone, this is completely normal. Don't let this get in your way though. Push through it as the feeling will pass quickly.
Am I doing this right?
As long as your test proves your code works, then yes, you are doing it right.
How much is enough?
This is a tough one to answer because only YOU know when enough is enough. You will learn over time what types of tests are valid and which ones are not. At a bare minimum you need tests that prove your 'happy path' works as well as edge cases.
Remember, writing tests for the first time is a lot like riding a bike. You are going to start slow, you are going to be shaky, hell my guess is you are going to crash into something. But like riding a bike, don't give up and you will be amazed by how quickly you get the hang of it.
Till next time,