Test stub generator...

lego1974's picture

Hello, I've written a perl script (fastens fire-proof suit) that generates module files as well as a test file complete with a test class and stubbed methods. I've posted the code as an issue to the simpletest module as webchick suggested: http://drupal.org/node/233261

From the documentation:

Features:
- creates a module folder and associated file skeletons
- generates a test class and test methods and places them in a test file
recognized by SimpleTest. This currently only covers unit tests,
and not higher level tests like functional or integration tests.
- can be re-run throughout module development
- if you add a new function to a module, rerun the script and a test
stub will be generated and placed in the appropriate test class
- works with existing modules
- adds hook_simpletest to an existing module

Issues:
- test stubs intentionally fail. I tried replicating PHPUnit's
TestNotImplementedException, but I didn't find a similar facility

Assumptions:
- the drupal coding standard is followed (generally, 1 tab == 2 spaces)
- a single module is defined per directory
- the module has the same name as the directory

Features Not Included:
- getters and setters for classes defined in module file
- class handling in general is not working, but the basic code is in place

TODO:
- complete handling for classes
- add handling for function removal by developer
- make template variables files - is this necessary?
- create CRUD scaffolds a la Ruby on Rails
- improve test coverage to include suites and further automation

Anyway, I hope you find this useful. I'm using it internally at my company. It eliminates a lot of the tedium of creating the tests. Note that it simply covers unit tests and not functional/regression/integration tests. There's lots that could be added. I'm hoping to get lots of feedback on it.

-Andy

Login to post comments

Komodo

andremolnar's picture
andremolnar - Mon, 2008-03-17 16:14

For people working in Komodo and didn't catch this on Drupal Planet I have put a couple of tools / ideas up on my blog.

http://becircle.com/blog_topics/komodo

There is a module generator macro and a snippet for creating test stubs.

andre


sounds cool for Komodo users!

lego1974's picture
lego1974 - Mon, 2008-03-17 21:03

Feel free to use any of the code in my original comment to do test stub updates and test file generation.