Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SimpleTest vs PHPunit

People also ask

What is PHPUnit used for?

PHPUnit is a framework independent library for unit testing PHP. Unit testing is a method by which small units of code are tested against expected results. Traditional testing tests an app as a whole meaning that individual components rarely get tested alone.

Is PHPUnit a framework?

PHPUnit is a programmer-oriented testing framework for PHP. It is an instance of the xUnit architecture for unit testing frameworks. The currently supported versions are PHPUnit 9 and PHPUnit 8.

Is PHPUnit open source?

#3) PHPUnitIt is an open source testing tool used for PHP code. It is the most widely used framework for unit testing.


This question is quite dated but as it is still getting traffic and answers I though I state my point here again even so I already did it on some other (newer) questions.

I'm really really baffled that SimpleTest still is considered an alternative to phpunit. Maybe i'm just misinformed but as far as I've seen:

  • PHPUnit is the standard; most frameworks use it (like Zend Framework (1&2), Cake, Agavi, even Symfony is dropping their own Framework in Symfony 2 for phpunit).
  • PHPUnit is integrated in every PHP IDE (Eclipse, Netbeans, Zend Stuide, PHPStorm) and works nicely.
  • Simpletest has an eclipse extension for PHP 5.1 (a.k.a. old) and nothing else.
  • PHPUnit works fine with every continuous integration server since it outputs all standard log files for code coverage and test reports.
  • Simpletest does not. While this is not a big problem to start with it will bite you big time once you stop "just testing" and start developing software (Yes that statement is provocative :) Don't take it too seriously).
  • PHPUnit is actively maintained, stable and works great for every codebase, every scenario and every way you want to write your tests.
  • (Subjective) PHPUnit provides much nicer code coverage reports than Simpletest
  • With PHPUnit you also get these reports inside your IDE (Netbeans, Eclipse, ...)
  • Also there are a couple of suggestings for a web interface to phpunit tests.

I've yet to see any argument in favor of SimpleTest. It's not even simpler to install since PHPUnit is available via pear:

pear channel-discover pear.phpunit.de
pear install phpunit/PHPUnit

and the "first test" looks pretty much the same.

As of PHPUnit 3.7 it's even easier to install it by just using the PHAR Archive

wget http://pear.phpunit.de/get/phpunit.phar
chmod +x phpunit-3.7.6.phar

or for windows just downloading the phar and running:

php phpunit-.phar

or when using the supported composer install ways like

"require-dev": {
    "phpunit/phpunit": "3.7.*"
}

to your composer.json.


For everything you want to test PHPUnit will have a solution and you will be able to find help pretty much anywhere (SO, #phpunit irc channel on freenode, pretty much every php developer ;) )

Please correct me if I've stated something wrong or forgot something :)

Overview of PHP Testing tools

Video: http://conference.phpnw.org.uk/phpnw11/schedule/sebastian-bergmann/

Slides: http://www.slideshare.net/sebastian_bergmann/the-php-testers-toolbox-osi-days-2011

It mentions stuff like Atoum which calls its self: "A simple, modern and intuitive unit testing framework for PHP!"


Full disclosure

I've originally written this answer Jan. 2011 where I had no affiliation with any PHP Testing project. Since then I became a contributor to PHPUnit.


I prefer PHPUnit now, but when I started out I used SimpleTest as I didn't always have access to the command line. SimpleTest is nice, but the only thing it really has over PHPUnit, in my opinion, is the web runner.

The reasons I like PHPUnit are that it integrates with other PHP developer tools such as phing (as does SimpleTest), phpUnderControl, and Xinc. As of version 3.0 it has mocking support, is being actively developed, and the documentation is excellent.

Really the only way to answer this question for yourself is to try both out for a time, and see which fits your style better.

EDIT: Phing now integrates with SimpleTest as well.


  • I could NOT understand how to download and install PHPUnit.
  • I could, however, easily understand how to install SimpleTest.

    (As far as i can remember the instructions for PHPUnit said something along the lines of "install it via PEAR and we won't give any instructions on how to do it any other way") see:

  • http://www.phpunit.de/manual/current/en/installation.html

For SimpleTest, just download it and point to it from your code.

So Simpletest won for me.


Half of the mentioned points in the accepted answer are simply not true:

SimpleTest has

  • the easier setup (extract to folder, include and run)
  • simply check the folder into version control (try to do that with phpunit nowadays :))
  • less dependencies and lots of extensions (webtester, formtester, auth)
  • a good code coverage reporter, which is easy to extend (dots, function names, colors)
  • a code coverage summary (finally landed in PHPUnit 4.x)
  • a decent web runner and an ajax web runner, with groups and single file executions
  • still better diff tool (with no whitespace or newline problems)
  • an adapter/wrapper to run SimpleTests by phpUnit and vice versa
  • compatibility PHP5.4+

The downside:

  • not industry standard (PHPUnit)
  • not actively maintained