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

CommentFileSizeAuthor
#1 unit_testing.zip4.7 KBchx
unit_tests.zip4.43 KBchx

Comments

chx’s picture

StatusFileSize
new4.7 KB

Once 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.

chx’s picture

If 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.

floretan’s picture

Step-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.sh and run-init-clearinghouse.sh to the scripts folder of your drupal directory.
3. From the drupal directory, run php scripts/unit_test_generate.sh. This automatically creates a unit_tests directory and generates stubs inside of it.
4. Run mkdir unit_tests/tests
5. Extract bootstrap.inc.test to unit_tests/tests/
6. Run php scripts/run-init-clearinghouse.sh.

At this point I get the error:

Fatal error: Cannot redeclare _password_base64_encode() (previously declared in /drupalhead/unit_tests/drupal_original/password.inc:48) in /drupalhead/unit_tests/drupal_stub/password.inc on line 10

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.

catch’s picture

@flobruit: This is the issue with password.inc http://drupal.org/node/249638

chx’s picture

Yes, 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.

chx’s picture

Status: Needs review » Closed (won't fix)

We 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.