Unit testing is a strange but now familiar beast. When I first started exploring the concept of testing code my brain began to race.
I need to test EVERYTHING! Trust nothing and no one.
Reality soon sank in that I wouldn't be successful if I thought that way. On some level I had to have trust or I would surely descend into madness. Ultimately I want to build successful applications.
So what have I learned to trust, and not trust?
Trust, but verify
You have to trust that your environment will function accordingly. If you are writing tests like the following, then you have real trust issues.
You have to trust that 3rd party tools will do the job they advertise. Sometimes they don't, but that is part of the research you do. There is no reason to test whether your instance of SQL Server is saving rows to the database.
Trust your assumptions are "correct". Sometimes this is harder than it looks, because assumptions can be wrong. Trust you are heading in the right direction, you can always pivot.
Trust your code. Trusting your code gets stronger with every relevant unit test. Confidence that your code will do the job is important, otherwise you are practicing "Faith based programming", and no amount of praying to the Code Gods will save you.
Trust your instincts. Users are not trained to think like you, they think on the macro level leaving out a lot of detail. It is your job to fill in those details.
Trust that things will break. I am not perfect and thinking so will just get me a bruised ego.
Input data will not always conform to your assumptions. It is hard to know the unknown. Sometimes stuff will just blow up. It's ok, fix it and back fill unit tests.
Code that isn't unit tested. You might feel good about the functionality in a method, but you still are gambling. Sometimes the gamble is worth it, sometimes it isn't.
A team member that breaks tests without fixing them is not to be trusted. It sucks, but they are putting your team and project in jeopardy.
Trust isn't binary, it is incremental. Everything in our world takes time to build our trust. This fact is no different in software development.I like to think of version numbers as identifiers of trust.
- < 1 : I don't know
- 1 : Ok, Maybe...
- 2 : We can hang out
- 3 : Sure, you can borrow my car
- 4 > : Can you watch my kids?
I like to think the applications I build are slowly gaining the trust of users, co-workers, and ultimately the domain that it exists in. Without trust what would we have?
As always follow me on Twitter @AquaBirdConsult. Trust me, you won't be disappointed :). Let me know you thoughts in the comments.