Lets say you write a function that given two numbers a and b it returns the sum of a and b.
Now imagine you write this function and at some point 3 months later another developer comes in and hanges that function to a minus b.
if your application uses that function when the new developer makes the changes your app wont behave the same way, resulting in bugs.
In order to prevent this kind of issues, we write another function that checks that you add function, actually adds numbers, we call this function a test function. A test function will fail if the code tested doesnt behave in the same say it was originally coded.
In here im using a retarded example of an addition function, but some pretty complex code ccan be tested, and there are two types of tests, unit tests and integration tests, i know that some professional devs dont even understand the difference....so im not gonna explain