Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")
Seems really obvious when I think about it, but has anyone here written an installer that runs a bunch of unit tests to make sure the thing installed properly? I'm writing a thumbnail generator part of which is a generic image class. One of the unit tests is:
public function testImageFormats() {
$image = new image();
$this->assertEqual($image->gd_support_gif, true);
$this->assertEqual($image->gd_support_png, true);
$this->assertEqual($image->gd_support_jpg, true);
}
When $image is created it gathers some data on what image functionality is available and sets the gd_support values ... if GIF creation isn't supported by the user's version of GD $image->gd_support_gif is false. While that's a useful unit test to check if my image class is working properly exactly the same check would also be a very useful during an installation process.
Has anyone considered taking Simpletest (or another unit test suite) and making an install script out of it?
That would be intelligent, especially to check if all the functions in your script are running properly on that server (different servers might not support some stuff).
Not quite, but I have an installer that runs the tests (subtle difference from how your post reads)
Our staging servers automatically update every hour with the latest versions from our repository (including tests) and runs the tests/specs immediately. We also use a loud comical family fortunes "eh-ah" when a test fails to alert us.
1. SimpleTest (and most other unit testing suites, I think) don't let you escalate errors. When you're installing an application, some errors will be fatal, others will merely be warnings (the user can still use the application, but some functionality will be degradeD).
2. Any unit testing framework means substantial bootstrap code that needs to be shipped with the application. Most people don't distribute a unit testing library with their code; with this sort of setup, you have to. An addendum to this is that most install scripts attempt to run with as few dependencies as possible: you don't want to have to run an install script to run the install script!
3. There's really no need to make an install script out of SimpleTest! Just make it really easy for users to run the unit tests after installation. The SimpleTest suite doesn't even need to know about the installer; it's an I (the installer) will call you (test suite).
I agree it's important for tests to be run, especially before shipping code, and it's important for tests to be run on a variety of platforms by many users. But I don't think most users will be interested in doing something like that.