So you don’t write tests, eh? This is what I think about it.
In a lot of projects I work in, the people just don’t write tests, especially in the frontend. And everytime the reasons are as follows:
- It takes so much time!
- It is much more code than the code I need to write for the app!
- We don’t need tests (because of reasons)!
And everytime the consequences are:
- SO MUCH SENSELESS BUGS!!! (😭😭😭)
1. The following line of code was added, without tests:
Question: what’s the value of
metaInfo.sendPrintjob === false ?
true 😞. Bug in production. A simple test most probably got that covered…
You could argue that the developer was stupid. But we all make mistakes. Writing tests allows us to execute that code VERY FAST and get IMMEDIATE RESPONSE. Without reloading the page, adding
console.logs, clicking through X screens just to get there and manually test it, maybe only once, like in this case with
metaInfo.sendPrintjob = true
2. Following code was changed:
This change led to a bug in production. I had to fix the bug ticket in a new project. And it did cost me hours of debugging to find it. As there were no tests at all, this means starting the app, clicking through lots of pages, and setting breakpoints just to get to the point I could reproduce… (this was a big codebase and I was new to the project)
Nevermind the frustation and lost of motivation on that day… But hey, thanks to the comment
Don't call toJSON!
If there was a simple test which expects that
toJSON has to be called, it wouldn’t be a problem at all..
Some arguments for testing
Tests are (living) documentation (= specification) - this means they are executable code documentation - see BDD on wikipedia
-> Do you always update the code docs when changing code?! (If your answer is yes: 😂)
Time! If you have no automated tests you need to manually test the whole app if you are making changes because you cannot know which parts you broke ;)
Refactoring: How can you refactor and clean up some code without automated tests? Manually test everthing? Good luck!
After updating dependencies tests can show you if something broke.
Better Code-Design - if you are writing tests, you think more about the structure of your code resulting in more clean and readable code
Fast feedback of code execution: You can run code without having to run the whole app. This can even speed up the development of a certain feature, especially UI related code. Who wants to click through 5 pages just to visit the part of the app you are working on?
Less bugs will go to production because with tests they are detected much earlier.
I hate to manually test my apps (of course I do it) but it’s just boring and error prone.
Writing tests will give you more confidence about your code.
🤺 …and yes you will have more test-code that production-code, but:
TDD is like Mr. Miyagi getting you to wash his car and paint his fence - seems like a lot of unnecessary work, but the payoff comes later pic.twitter.com/7U9nbENXEU— Joshua Morony (@joshuamorony) June 14, 2017
Writing unit tests for personal projects? - FunFunFunction #29 @ YouTube -> “Code without tests is buggy and bad code”
Eric Elliott - 5 Questions Every Unit Test Must Answer -> “Most Developers Don’t Know How to Test”
Eric Elliott - 5 Common Misconceptions About TDD & Unit Tests -> “TDD is too Time Consuming”
So, always remember: