Differences between revisions 9 and 10
Revision 9 as of 2011-10-12 01:04:11
Size: 3003
Editor: ip174-69-125-42
Revision 10 as of 2011-11-16 10:17:02
Size: 2957
Editor: 194
Comment: Removed spam links.
Deletions are marked like this. Additions are marked like this.
Line 48: Line 48:
[[http://www.myownasp.com|Quickbooks hosting]]

Writing unit tests for log4php

So how do you get started?

  1. Install the latest version of PHPUnit

  2. Install the latest version of XDebug

  3. Checkout the latest source code
    svn co http://svn.apache.org/repos/asf/incubator/log4php/trunk log4php-trunk
  4. Run the unit test suite
    cd log4php-trunk/src/test/php
    A code coverage report is created inside target/test/report.
  5. Open up target/test/report/index.html in your browser and have a look what's covered by tests and not.
  6. When you find something to test create the according ClassNameTest.php file inside src/test/php/ (the directory layout is the same as you see in src/main/php but using Test.php as the end of the filename).

  7. Write the test cases
  8. If you have commit access just go ahead and submit your new test cases when it runs fine and cover new code. If you don't have commit access simply do:
    svn diff > something.patch

    and hand that file over to log4php mailing list so one of the committers can review and commit it.


  • Have a look on how other unit tests are written before you start writing your own tests.
  • Use self::markTestIncomplete() to mark incomplete unit tests.
  • To execute just one test class use
    phpunit LoggerLevelTest.php

Running xdebug on a mac

Mac users don't have an easy life with xdebug. For example MAMP cannot be used easily a custom install is necessary.

Using Entropy.ch PHP

Entropy.ch is providing precompiled PHP packages for Tiger (a bit outdated but works for Log4PHP) and Leopard. Even an precompiled Apache can be downloaded. See: http://www.entropy.ch/software/macosx/php/

After installing it on your system under /usr/local you just need to set your .bash_profile variables:

# Set enviroment for Entropy Apache 2 and PHP 5.2.x PATH=$PATH:/usr/local/apache2/bin:/usr/local/php5/bin

and you'll need to upgrade pear:

$ pear upgrade PEAR

Then follow normal instructions above. This worked out for Tiger.

From Scratch

You need to compile Xdebug on Mac (binaries are only available for Windows) and in order to do that you need to have necessary tools and header files installed. The basic requirements for compiling PHP extensions is the same as for PHP itself (see: http://www.php.net/anoncvs.php)


I prefer MacPorts [1] as my package manager on OS X since that's the easiest way to get all needed tools and header files. There's too many tutorials on this [2] so I won't go into details. But at least you will have to do this:

$ sudo port install php5 +apache2 +mysql5 +pear $ sudo port install php5-devel

Some of the basic tools like gcc etc is installed with Xcode, but most of what you need is also available in MacPorts.

WritingTests (last edited 2011-11-16 10:17:02 by 194)