Category 1: I Don’t Understand the Code Under Test
Excuse:
“If I wrote tests, it would require me to understand my code.”
“I don’t understand how the code is supposed to work.”
Rebuttal:
“Writing tests before, during, or after writing the code will help you understand it better. Give it a shot.”
Category 2: I Don’t Like a Certain Type of Test
Excuse:
“I don’t like writing tests that consist of lots of mocks.”
Rebuttal:
“If you don’t like writing tests with mocks then don’t write tests with mocks. It’s that simple.”
Category 3: I Will Write Tests Later
Excuse:
“I get excited about the problem and want to jump into solving it.”
“Let me just add this little feature, then this, then that, then I will write my tests.”
Rebuttal:
“You do not have to follow TDD religiously.
Using the mountain climbing analogy, you can compare tests to “climbing holds” rock climbers attach to rockfaces.
The climbing holds (tests) can save your life if you have a climbing accident and even if that never happens (praise God), they give you the confidence that you are safe when taking on new challenges. Same thing with tests (ala regression tests etc).”
Category 4: Test Writing Skills
Excuse:
“I don’t write tests because I don’t know how to.”
“Designing good tests is a skill which I don’t have.”
Rebuttal:
“How do you know your code is working as intended if you cant codify it? WRITE TESTS!”
Category 5: How Much Tests is Enough?
Excuse:
“I can’t determine what good test coverage looks like.”
“I don’t write tests because I can’t write flawless code so what’s the point of tests?”
Rebuttal:
“Software is never done as you keep adding features and fixing bugs.
Therefore, perfection is not an act but a habit.
So create a habit of writing tests.”
Category 6: It’s Not the Right Time
Excuse:
“I am prototyping so there is no need for tests.”
“I am writing throwaway code.”
“95% of what I write is proof of concept and speed of development is a top priority.”
Rebuttal:
“In cases like this, not writing tests is fine.
Although you do realize that you are still manually testing your code to be sure it works.”
Category 7: Code Structure
Excuse:
“I don’t test because my code isn’t very testable.”
“I don’t test because the legacy code I work on isn’t testable.”
“I don’t know how to convert my existing code so that it can be tested.”
“All the code was written in the Waterfall days and was manually tested and isn’t testable in the Agile short cycle days of today.”
Rebuttal:
“It may be impossible to unit test but you can write system tests for the entire system.
If the code is untestable like you say, then it must also be unusable to users.
How do they then know the system is working?
Be pragmatic, testing is better than no tests.”
Category 8: Project Structure, Time and Budget
Excuse:
“There is no test infrastructure in the project due to its legacy nature and there are no spare resources to correct this.”
“Due dates don’t allow for feature development let alone tests.”
“Clients don’t recognize the value and don’t want to pay for the test development time.”
“It takes 3 times the time to write a test suite than the feature itself.”
“The client wants the feature by the date, not the test.”
Rebuttal:
“There is a misunderstanding that writing code with tests is slower than writing without tests.
This is not true.
Any code you didn’t just write can be termed legacy code and to be doubly sure that what you are writing doesn’t break your legacy code, you need to write tests.
P.S: If you get into trouble for writing solid tests at work, then you should find another job.”
Category 9: Ignorance is Bliss
Excuse:
“If I don’t write tests, I won’t have to deal with failing tests.”
“If I don’t write tests, I won’t be able to spot bugs therefore my code would be bug-free.”
“I don’t write tests because customers are the tests - David Beazley”
Rebuttal:
“This is cheating as testing and coding go together.
You can’t wait to only fix bugs that your customers report to you.
This isn’t good software development practice.”
Category 10: Workflow Interruptions
Excuse:
“Writing tests forces me to create and analyze at the same time. These are two different mindsets and the shift is counterproductive.”
“Test suites take too long to run.”
“The tests are too slow.”
Rebuttal:
“There are ways to speed up the test suites.”
Category 11: Perception of TDD
Excuse:
“TDD has a bad rap, with too many adverts and misinformation.”
“TDD is not for the impatient, it’s for developers who want solid results.”
“I am self-taught and the resources I learned from didn’t emphasize testing.”
“I was never taught TDD and consider it an advanced topic.”
Rebuttal:
“These impressions are wrong.
Completely wrong.
TDD is an essential skill every developer should strive to have.”
Conclusion
Testing and development are part of the same thing.
We have to think of what the code is supposed to do and we also have to ensure that the code is doing what it is supposed to do.
This is what software development is.
References:
Test & Code in Python Podcast - By Brian Okken