A few years ago I was interviewing candidates to join our team. The interview was going well. The gentleman being interviewed was likable and answering questions well. When the subject of testing and test driven development came up he just rolled his eyes and said he hated testing.
The interview continued with a few more questions and then it ended. The candidate had effectively eliminated himself.
The job description clearly stated that the team practiced TDD. It was mentioned during the opening introduction of the interview. This should not have come as a surprise. The candidate was not prepared. The candidate was not a mature developer.
I get it. Testing isn’t fun. Testing can be difficult. Testing can be scary if you’ve never done it. We as developers are paid to know. We’re paid to have the answers. It’s scary not knowing the answers. But, we’re professionals. If we don’t know, we should find out. Even on our own dime and on our own time.
The jury is in. The controversy is over. The debate has ended. The conclusion is: TDD works. Sorry.
— Uncle Bob
There are a variety of tools for the .NET developer. NCrunch is a great 3rd party continuous test runner. ReSharper with dotCover also offers a continuous testing feature. Live Unit Testing in Visual Studio 2017 Enterprise offers much the same functionality. Even without Enterprise, other versions of Visual Studio and VS Code offer a test runner.
So, why do those that don’t practice TDD ignore the practice? Why do those who have never tried not learn? There isn’t much incentive if you don’t work on a team that is practicing TDD. Test Driven Development is a personal practice, but one that must be learned.
I think it boils down to fear. Fear of the unknown. Fear of failure. That, or just plain laziness.
Benefits of TDD
The benefits of TDD and writing good unit tests are many. TDD reduces the effort of manual testing. The practice can also help reduce the bug count of a system. Test Driven Development also removes the fear of refactoring.
Reduce Effort of Manual Testing
So how do you ensure that your application works without writing tests? Do you have to launch the web application? Setup a scenario in order to verify your change or enhancement works? Navigate deep into the rest of the app to ensure correctness?
Through TDD you can ensure some level of correctness without ever running the application. By writing a few tests you can verify your algorithm works as expected. What’s better, you now have the beginnings of a test suite to cover any regression testing.
Reduce Bug Count
If you’re manually testing your application, do you test the edge cases or just the happy path? How do you know your change didn’t effect the rest of the application? Did the change you just introduced cause a bug in another part of the system? Growing an application through tests will help discover potential errors in logic and help to eliminate issues before they make it into production.
Remove the Fear of Refactoring
Maintenance costs can grow to consume a large portion of a project’s budget. Refactoring without tests can be a scary proposition. However, if your application is covered with a comprehensive set of tests the fear of refactoring can be all but eliminated.
How to get started?
Find a mentor. Read a book. Find a class. Watch a video. Practice, practice, practice.
If you’re working on a team whose members are already practicing TDD it can be quite easy to get started. However, if you’re going solo it can be a challenge. Don’t fret, we all started somewhere. If you’re struggling, feel free to reach out in the comments below.
Here are a few resources to help get you started:
An International Speaker, Author, and Microsoft MVP, John has been a professional developer since 1999. He has focused primarily on web technologies and currently focuses on C# and .NET Core in Azure. Clean code and professionalism are particularly important to him, as well as mentoring and teaching others what he has learned along the way.