Over the past several years, I've heard a common refrain from folks: "We want to do unit testing, we just haven't found time for it."
It's understandable; I've said it myself many times, even recently. Testing is easy to push off. Your code won't break just because there aren't unit tests. The functionality doesn't improve based on your test coverage number.
I think one issue people run in to is the plethora of choices out there. They get stuck before even getting started, thinking to themselves:
My answer to all of the above is: YES! Yes you should use a framework and write in a style and have some sort of code coverage and yadda yadda. Which one you use doesn't matter nearly as much as you actually using something.
- Should I use Jasmine, Mocha, Tape or some other test runner?
- Should I write in BDD, TDD or Gherkin/Cucumber style?
- Should I use Karma, Testem or The Intern?
- What level of unit test coverage should I aim for?
- Should I include my tests next to my scripts, or have them in a separate 'test' folder?
Truthfully, the popular options out there are all pretty awesome. No matter the tool you pick, I guarantee you'll learn amazing things about your code. You may say something like, "Next time I want to try using something different", but you'll never say, "I regret writing those tests".
Testing is as much about catching regressions as it is about finding and eliminating technical debt. It forces you to look at your code and find where functions are doing too much, where documentation is unclear, and where requirements aren't well defined.
So if you find yourself wishing you wrote tests, just start testing. Pick a tool, don't debate about it, and try it out. You'll learn more about your code in those few hours than you have in weeks.