Strange Symphonies The whole is greater than the sum of its parts

Related tags

15May/101

Beginning WordPress Automated Testing

I've been a heavy user of WordPress. This blog has been using WordPress for almost the past five years. I've developed multiple plugins and themes for WordPress. Plus I've been a heavy advocate of WordPress for many of my clients work as that is all they really require.

Though I've been a heavy user, I haven't really contributed code to WordPress.

Coming from a Ruby on Rails background, I was familiar with testing. Whilst working with WordPress, I felt a bit insecure that there were no available tests out there.

Lucky for me, with a bit of research I found WordPress did have Automated Testing. When first running the tests, I didn't get 100% success rate. Now this freaked me out.

Soon I learned that sadly not all the tests pass, and the test are outdated. Hopefully there will be plans to update the tests, but in the mean time, here is how to get the tests started.

Dependencies:

  • SubVersion
  • PHPUnit
  • Empty MySQL Database

Installing PHPUnit

WordPress Automated Testing has a dependency on PHPUnit, so we are required to install the package.

Open up your terminal, and as root execute:

pear channel-discover pear.phpunit.de
pear channel-discover pear.symfony-project.com
pear install phpunit/PHPUnit

Installing WordPress Automated Testing

Pull down the Automated Testing code like so:

svn http://svn.automattic.com/wordpress-tests/

This should create a wordpress-tests folder. Now go inside it.

Create a MySQL Database

The WordPress Automated Testing requires an empty database. That means the database should have no records, no tables, nothing.

I simply created a new MySQL Database called wordpress-tests:

mysqladmin -u root -p create wordpress-tests

Now we are almost good to go.

Configuring WordPress Tests

Inside the WordPress Tests directory, copy the wp-config.sample.php to wp-config.php. This configuration is similar to normal WordPress installations. Fill in the necessary details, and you are almost good to go.

Running Your Tests

Once your tests are configured, you can run the tests via executing:

php wp-test.php

Failing Tests

Don't be surprised that some tests fail. Apparently its a normal thing. I messaged the WordPress Testers Mailing List about the tests failing. Judging from the reply I got, apparently its "right".

My test failure rate is:

FAILURES!
Tests: 489, Assertions: 2919, Failures: 136, Errors: 32, Skipped: 18.

Overall it takes about 6 and a half minutes to run.

Conclusion

There you have it, automated testing for WordPress. Hopefully by posting this, more and more people will contribute back to WordPress, and improve the automated testing.