+ 2
The importance of testing
So I'm currently building a REST API using express, and I have always been curious and interested in applying tests to my code one day, I decided to use jest and started to implement some tests to my API, but U have a few concerns and uncertainty about the importance of any of that tbh. testing sounds important, but I feel it wouldn't be that useful to me. Besides, writing tests feel dull and tedious. So I was hoping I would find some answers from you that either motivate me to continue writing tests, or maybe give me an idea of how to make writing tests more attractive
3 Answers
+ 5
Now if it's a mini code, like 'write a function that calculates the BMI', you might be lazy and just do the 4 or 5 inputs for testing manually each time.
For a 100 liner, we might already be talking about a dozen or more test inputs.
Now imagine a 1000 lines.
Do you want to manually test the same 100 inputs every time you change a little thing?
Now imagine actual softwares that might have millions of lines of codes, countless modules, and many, many people work together, sometimes over a decade or longer, potentially messing things up for each other.
It would be simply impossible to manually test all the crap that could happen at any point in the life of the software.
In short: It may be annoying to write a whole bunch of tests *once*, but it will be way more annoying testing the same stuff a hundred times manually.
+ 5
Let's state a few general things.
Consider some little code project, 50 to 100 lines, as we do them when we're learning.
You are finished with the 'draft' and figure out if your program does what's it supposed to you.
Of course it doesnât. ;-) So what do you do? You debug. That can be a LOT of work even for a small piece of code. First you need to find the issue, then find a solution, then try the whole thing with all sorts of inputs to see if it works.
You'll likely spend more time debugging than writing code, commenting in and out stuff, switching stuff around, writing things new, implement unnecessary outputs so you see where the values change (although ideally you'd use a debugger).
After you think you've made it, you need to test all possible input values again - because you might have accidentally created another mistake.
For every little change, you need to do it all over again.
Now imagine you write all critical tests *once* and henceforth just hit 'run' everytime you make a little change.
+ 1
You brought up some good points HonFu , I think I will apply tests to my current project just to acquire the skill at least.
And in the future I'll try to implement only if I know the project will be quite big, for small projects it would be a waste of time and effort đ
Thanks a lot !