Unit testing your code is easy – all you need is to write simple test code and run it from time to time to check if your code misbehaves. But there is more to successfully using unit tests then just write these tests, in fact I saw quite a few talented developers get frustrated and stop unit testing for several reasons.
I don’t think that there is a single factor that can cause the success (or failure) of unit testing integration as much as your team.
The Team factor
Your co-workers and your team leader are the ones that will cause your unit tests to be effective or just a waste of time (or make you feel that way).
Unit testing the code is just not as much fun when you’re the only one doing it, all is needed is for someone else to commit a change (without running unit tests) and you’re back to trying to find out why your tests stopped working.
Unit testing is a team sport and like other team sports it is much more fun with the whole team. Shooting hoops is ok but playing basketball with your team will be much more fun!
When you got your all team onboard the whole “unit testing” experience (or better yet TDD) things get much more easier. If every member of your team is responsible to run the project’s tests before commits the build will break less.
In a nutshell – it’s nearly impossible to keep using unit tests when you’re the only one doing so.
There are other benefit of getting your team support:
- Test reviews – improve your skills by by reading your fellow developer test code and by having your code reviewed . This is exactly the same as learning best practices from code reviews – for tests.
- Track improvement – in order to show management and other teams in your company that your project improve because you use unit tests you need to be able to measure the actual improvement, when the team works using the same methodology it becomes easier to measure success.
How can it be done
Luckily for me my employer is a big believer of agile methodologies and that developers should write unit tests, but what if you’re the only one that seen the light and you want to show your team how software development can benefit from unit testing?
Depending on the organizational culture of your company you might want to try and pitch the idea to your boss, team lead or friendly neighborhood architect, if you have an ally that can help you convince the rest of the team.
Or you can start from your co-workers and convince them to join you and see if it makes your work better.
Use facts and explain why this is a good change, because there is nothing more convincing then actual experience try to suggest a “trial period” to see if unit testing is good for your organization.
If you want to learn more about how to implement unit testing in your team – you will find this webinar interesting.