Back to Resources


Posted December 1, 2011

A Brief History-In-Progress of Running Tests in Parallel with PHPUnit

  • PHPUnit is great.

One of the great things about PHPUnit is that it does its job so well that there’s only one notable testing framework for PHP. Other languages have messy competition between multiple frameworks, and PHP gets to have just one.

  • Like most testing frameworks, PHPUnit runs tests one-at-a-time.

This makes sense because unit tests are usually fast and so you don't have to wait for them to finish. But these days, many PHP shops also use PHPUnit to kick off their Selenium tests. And because Selenium uses real browsers and exercises the entire end to end system, they are by nature much slower than unit tests. And herein lies one of the biggest speed bumps preventing PHP shops from delivering new code to their users quickly. Here comes the metaphor!

Your tests are people, and running them is feeding them. They all want to eat at the same time (lunch time is build time.) They get in line at the hot dog stand, run by the hot dog vendor, PHPUnit. PHPUnit quickly hands each of them a preheated hot dog, one at a time. Everybody gets fed.

Then you find out about this new kind of person, the Selenium test. They’re more powerful, but their meal takes a long time to finish. No problem! You give PHPUnit the facilities and training to make Selenium food by downloading PHPUnit_Selenium. But now, each time it’s a Selenium test’s turn in line, everyone has to wait for it to finish.

So maybe you heard about this restaurant across the street called Sauce Labs that specializes in Selenium food. They have hundreds of chefs waiting to cook for you. So you tell PHPUnit to use Sauce Labs.

But PHPUnit was brought up in a world of hot dogs, without Selenium or Sauce Labs. It doesn’t know how to multitask. It leads each Selenium test over to Sauce Labs alone, then sits next to it and watches while one Sauce chef cooks and 499 Sauce chefs anxiously twiddle their thumbs. PHPUnit needs to send all the Selenium tests to Sauce Labs at the same time, to take advantage of the idle Sauce chefs and get everyone fed in faster.

Many people, including several of our customers, have already realized how valuable PHPUnit parallelism would be. They built their own parallelism support in-house. In particular, PBWorks’ OMGUnit, built on top of PHPUnit, launches their test files simultaneously to take advantage of Sauce’s cloud capacity. That’s great for you if and only if you’re PBWorks, or one of the many PHPUnit users who have cooked up your own system that runs on top of PHPUnit. We don’t want all our customers to have to suffer those indignities. We wanted a parallelism solution to hand to all our customers, that works out of the box, regardless of setup. I talked to PBWorks, and they graciously open sourced OMGUnit. The original plan was to make OMGUnit general enough to hand to our customers. I played with it until I felt like I had a handle on how parallelism works, but I realized there was a bigger opportunity here. The demand for PHPUnit to support parallel testing was risking PHPUnit's future as the One And Only PHP test framework, and it didn't have to.

  • So we contributed parallel test execution to PHPUnit core.

It's fully cross-platform. As of Nov 30, 2011, it has not yet been released, and I probably have more work to do before it gets released. But you can get a working preview of it today! More on that later. Once it's released, you can run PHPUnit tests in parallel with a command line parameter:


or with the following attribute on your TestCase class:

/* * @runTestsInParallel */

where is the maximum number of processes you want PHPUnit to use in parallel.

  • It's due for release in PHPUnit 3.7

In the meantime you can get a preview version of it from the Sauce pear channel, but it's built off of some old versions of PHPUnit's supporting libraries. There are steps for getting it working in our docs.

  • UPDATE: Parallelism will not be available in PHPUnit 3.7

Sebastian, the reclusive founder and maintainer of PHPUnit, has changed his mind. He is interested enough in concurrency that he has generously decided to rewrite it himself.  What this means for you is that PHPUnit's internal parallelism code will be much better written, but you will have to wait a little longer. His current plan is to release it before April 2013.

Dec 1, 2011
Share this post
Copy Share Link
© 2023 Sauce Labs Inc., all rights reserved. SAUCE and SAUCE LABS are registered trademarks owned by Sauce Labs Inc. in the United States, EU, and may be registered in other jurisdictions.