Unit and regression testing with PHPUnit

acmoore wrote on Thursday, June 03, 2010:

I submitted a patch to fix a small bug I found in one of the classes:

https://sourceforge.net/tracker/?func=detail&aid=3011235&group_id=60081&atid=493001

But, the interesting part of the patch is that it includes some test cases that use PHPUnit. This tool lets you write unit tests that run pieces of your code and compare the results to the expected results. I find it useful to show that my code is doing what I intend for it to do, and to prevent me from breaking stuff that already works.

Do the other contributors feel that we could benefit from having these types of tests on the code? If so, I can work to expand this type of tool so that it can be used to test the more complex parts of the application, such as functions that hit the database. I’m also willing to run a continuous integration server to periodically run these tests and indicate if any of them start failing. I’m hoping that will help us make sure that we don’t unexpectedly break things.

-Andy

stephen-smith wrote on Thursday, June 03, 2010:

Unit testing is always good, we just need to keep false failures down.  We should also concisely document how to run the tests.  Ideally anyone doing a CVS checkout or Git clone would run the tests to ensure that the HEAD they got works in their environment.

As long as PHPUnit isn’t required for running the code in production, this doesn’t really add a dependency, so it should be fine.

I’ll look at the specific patch in just a moment.

acmoore wrote on Friday, June 04, 2010:

Those are good points. I’ll add in some documentation, and perhaps a Makefile or something like that to help folks use the test suite.

Thanks also for your comments on the patch itself. I replied to those in the tracker and will try to address them in code soon.

-Andy