ChapterÂ 8.Â Testing
Hacks 79â85: Introduction
Application testingâand squeezing that testing into what are almost always strenuous development cyclesâhas been a hot topic in recent years. This chapter starts with unit tests, which test an applicationâs individual functions and classes. Then weâll move on and cover automatic generation of unit tests, as well as the testing of an application through alternate means. Youâll code up robots that make HTTP requests to a server and tests that use Internet Explorer automation for checking a web interface for problems.
Test Your Code with Unit Tests
Use PHPUnit and PHPUnit2 to test your code continuously.
PHP is quietly becoming a force in enterprise application development. With larger applications come more complexity and requirements for testing in an attempt to make sure that the application is stable. Itâs a truism that stable applications are built by creating a multitiered structure, with each layer well tested on its own. For example, you might have a self-contained database layer (that is tested) that sits underneath a business logic layer (that is tested), which in turn is used by the user interface layer (that is also tested). Starting to get the idea?
To test each layer, it has become common practice to create unit tests. These are tests that are run after any code change and before any code is checked in (you are using version control on your enterprise projects, arenât you?). In fact, itâs common to insist that ...