[wp-hackers] Unit Testing, Yet Another Discussion

jacobsantos at branson.com jacobsantos at branson.com
Wed Aug 1 18:28:46 GMT 2007


Everything I've found has stated that Unit Testing isn't something that 
WordPress does, or *thinks* is impossible for WordPress. I hope I'm not 
beating a dead horse, but I really do think this should be actively 
pursued to improve the quality of WordPress.

Regressions be be avoided with unit testing. Theories and bug fixing can 
be improved. Unit Testing is not just for classes and methods. My unit 
test for the Plugin.php file proves this. You don't have to test what is 
in the function, just the result. If the result is not what you 
expected, then something in the function changed or is wrong.

One of the best advantages of using unit tests is writing tests for 
bugs. I don't think anyone can write an unit test that covers 
everything, including the interactions. To illustrate this point, the 
coding that I'm doing with WordPress has mostly been developed using 
Unit Tests, with functions and with classes.

I think the next Summer Of Code should involve Unit Testing WordPress 
wp-includes and/or functional testing of WordPress pages. The quality of 
WordPress releases should improve greatly.

--------------------

#1: The question I should ask is what is needed to get the ball started? 
I'm willing to write unit tests for wp-includes, that I work with, when 
I get to them. However, since I'm not a core developer, I have no 
motivation to start such a project. Which might be a lie. Damn, I guess 
I could use this to learn better Unit Testing and perhaps try Functional 
Testing.

#2 If someone did write a complete unit testing suite of wp-includes 
code (about 70%-80% code coverage), would that be used actively by 
testers and developers? There is no point putting work into something 
that would only be used by one or two people.

#3 Has anyone else (besides the guy building the functional testing with 
SimpleTest, which is massively incomplete) started or finished their own 
unit testing suite of WordPress?

-------------------

It wouldn't be difficult to finish the unit test that I have for 
wp-includes/plugin.php, I think also it would be a good idea to check 
the previous commits and see what regressions were made by the recent 
2.2.1 changes. Well, I only have about 30% code coverage of the plugin.php.

Oh, the discussion about Test Driven Development is not needed. If you 
write unit tests enough, you'll naturally fall into TDD, but for others, 
it could just be that a few people write unit tests after the code was 
committed or for new bugs. So even if you don't use unit tests for 
development, it doesn't mean that it wouldn't be useful currently and in 
the future.


More information about the wp-hackers mailing list