Testing is a very important and indispensable technique when writing good quality code. It makes sure that developers can test code repeatedly and automatically, for example, after the code was modified or when it runs in a different environment. Therefore, testing makes your code scalable, maintainable, and hopefully bug free.
Often, tests of a software are also seen as a documentation of the code because the tests show the proper usage of the code with all possible arguments and options. Moreover, this documentation is always up-to-date and executable, which is a huge advantage to static documentations.
In general, there exist multiple levels for software tests: