Appendix A. Tools and tips for testing

 

This chapter covers:

  • A.1 The basics 493
  • A.2 Organizing tests in a directory structure 495
  • A.3 PHPUnit and SimpleTest assertions 496
  • A.4 SimpleTest web test API 498

The testing chapters in this book primarily deal with the process, principles, and logic of testing. Therefore, we’ve saved some juicy details for dessert, focusing on how to do specific things in the two most popular unit testing frameworks, SimpleTest and PHPUnit.

A.1. The basics

Basic examples of how to use SimpleTest and PHPUnit are available elsewhere, but just to make sure we get the mechanical aspects right and don’t get bogged down in some stupid error situation, we’ll do an ultra-simple example that is neither conceptually challenging nor useful. We’ll do this in SimpleTest first and then in PHPUnit.

Brain-dead SimpleTest example

We’ll test the workings of the PHP date() function with a couple of simple assertions. Listing A.1 shows how this is done. Most of what is going on in it has already been explained in chapter 9. The example is included here for the sake of comparison with PHPUnit and to provide a test that can be run exactly the way it is, since it contains the code to be tested as well.

A.2. Organizing tests in a directory structure

A.3. PHPUnit and SimpleTest assertions

A.4. SimpleTest web test API