We are humans, we forget, we make mistakes, we change things, ideas. This happens when we work solo, imagine when you are in a team!
When we add new features or edit previously written code, we can create some issues in the other part of the application. Wouldn't it be cool if someone could check for you that everything is fine or you have broken 3 modules of x or y class, function, or whatever?
Yes, it takes time. For example, TDD takes a little bit of time, but if you count the time that you will not spend looking for bugs after you find that 50% of your application is broken, it is better.
I would say that it will take a little bit of time in the beginning, but in the end will take less time. If you code without testing when you have a full production application when you add a new feature breaking parts of your application, I'm pretty confident that you'll have a harder time.
The beautiful thing about testing is that you are able to follow the exact point in which your function has problems.
Yes, you guessed it, this is the purpose of testing... We are not perfect. Testing allows us to check that every behavior is exactly how we have coded it. The function receives the same inputs and gives the same outputs; the overall application works as intended.
If you could catch minor problems before they transform into huge loopholes in your software - I think that it's fantastic.
If you don't, a simple bug after days and days, weeks, months, more people working on the project, and you have to solve a huge problem that you could have solved by implementing some tests.
Another important benefit of testing - it helps your team understand more about the x or y function since you will have a descriptive name that gives the reader what you are testing.
I suggest you follow the Test-Driven Development process - before you write any function that you want to test, you begin by creating the test! You write a test for that function with the main goal that you want to achieve in your mind; then, you develop the function.
There are many types of testing. The one that I've described is a unit test. There are many types of testing.
Unit Testing focuses only on a single unit, as the name suggests, and it doesn't care about the connection of your function with other parts.
I've learned about testing from many sources that I cannot recall now, but one book that I remember for sure is Clean Code!
Watch my youtube video here: