Testing code through automated tests is important to ensure security and catch bugs early in the development process. There are different types of tests like unit tests which test individual functions and modules, and functional tests which test overall page behavior and interactions. Writing tests requires considering what to test, test organization, and dealing with limitations of testing tools.