The generating script is boombatower's work I just cleaned it up and turned it into a script. The clearinghouse is basically mine -- Jimmy has written a test runner for it but it was not really working. This on kind of does though at this moment I hardwired the bootstrap test into it. It's a piece of cake (copy-paste) to make it pick up tests instead of hard wire. So, drop the scripts into scripts , run the generator, mkdir unit_tests/test , drop the bootstrap test into unit_tests/test and php scripts/run-unit-clearinghouse.php you will get one failure. Now go ahead and edit the bootstrap test, $filename = 'modules/system/system.module'; and rerun , you will get one pass. Now, go ahead and write a couple thousand unit tests the stubs are giving you a hint :D
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | unit_testing.zip | 4.7 KB | chx |
| unit_tests.zip | 4.43 KB | chx |
Comments
Comment #1
chx commentedOnce http://drupal.org/node/249629 is in, this one here actually picks up tests from unit_tests/tests automatically. One further enhancement could be replacing glob with Directory.
Comment #2
chx commentedIf we find exact matching too strict, we could also add an 'extended matching' key to the step array (besides incoming and return) and then make the incoming array contain stuff like
array('match' => 'callback', 'value' => 'is_array')or anything else we want to.Another problem we have here are that you need to list default arguments. I imagine one could extend the parser to add arguments to the test stubs.
Comment #3
floretan commentedStep-by-step instructions for using the files from the zip archive in #1.
1. Apply the patch from #249629: Make drupal_test_case reusable.
2. Extract
unit_test_generate.shandrun-init-clearinghouse.shto thescriptsfolder of your drupal directory.3. From the drupal directory, run
php scripts/unit_test_generate.sh. This automatically creates aunit_testsdirectory and generates stubs inside of it.4. Run
mkdir unit_tests/tests5. Extract
bootstrap.inc.testtounit_tests/tests/6. Run
php scripts/run-init-clearinghouse.sh.At this point I get the error:
Commenting out that _password_base64_encode() function in unit_tests/drupal_stub/password.inc lets you run the tests. I need to look into what is happening here, but I also need to get some sleep first.
Comment #4
catch@flobruit: This is the issue with password.inc http://drupal.org/node/249638
Comment #5
chx commentedYes, the password.inc issue should be fixed in HEAD. Thanks for the step-by-step instructions. Edit: the zip file contains the paths so if you just unzip it from your Drupal dir then files theoretically end where they should.
Comment #6
chx commentedWe think there are not enough resources to build unit tests. Too many and too fragile. To use a mine as an allegory, we do not have the resources to build and maintain a fine mesh of sensors on the wall -- but a canary is still better than getting the miners dying down there. Let's go and feed the canary, then.