One of my personal missions over the last six months has been to shave seconds off of the WordPress and BuddyPress automated test suites. (WP’s tests run in under half the time today than in WP 4.0 – and with the addition of nearly 1000 tests. Score!) One of the tools I use to track down problematic tests is John Kary’s excellent phpunit-speedtrap, which adds a listener to each test run, and produces a report of tests whose running time exceeds a configurable threshhold. phpunit-speedtrap is designed to be used as a Composer dependency, but this is not currently convenient or necessary for the purposes of working with WP/BP (for one thing, I’m the only person doing it). Here’s how I’ve rigged it up to run locally:
- Grab a copy of the listener class from Github https://github.com/johnkary/phpunit-speedtrap/blob/master/src/JohnKary/PHPUnit/Listener/SpeedTrapListener.php. I chose to remove the PHP namespacing, but you can do as you wish. Save it somewhere – I put it at
~/.speed-trap-listener.php
so that I can use it with all projects. - WP and BP ship with a
phpunit.xml.dist
config file. The.dist
extension means that you can run your ownphpunit.xml
alongside ofphpunit.xml.dist
– PHPUnit will prefer the non-dist version if available, while WP and BP’s version control config will ignore it. Copyphpunit.xml.dist
tophpunit.xml
and add the following block:
[code language=”xml”]
250
Change theslowThreshold
and filepath to whatever you’d like. - Run
phpunit
. You’ll see something like this:
Keep on shavin’!